AetX
AetX

Reputation: 213

How to link a C++ library in a C project

The c project is composed by a lot of classes and files. The C++ library is compiled into a ".a" file. When I add the .a file as library to the MakeFile of the C project, it shows a lot of errors like undefined reference to '__gxx_personality_v0' that may related to the difference between C and C++.

I'm using gcc to compile the C project. But whatever functions I'm calling in the C project are declared as extern C in the header file of the C++ library.

I really appreciate any help!

Upvotes: 2

Views: 1188

Answers (1)

Matthieu Brucher
Matthieu Brucher

Reputation: 22023

You have to use a C++ linker, or use g++ as the link driver instead of gcc.

The issue is that the basic linker will not link against C++ runtime libraries (the same would be true for a Fortran static library). The C++ driver for your compiler will add these flags for you.

Upvotes: 3

Related Questions