2

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!

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Does main have to be C++ for that, or does it also work if main is C?
No, you can have any type of main. It's just the runtime libraries, what C++ needs to run, that you have to integrated s they are not in the static library.
Thanks! Compile with gcc and then link with g++ solved the problem!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.