Another C / C ++ integration issue: I'm trying to update some deprecated C library (let it libcl.a ) with the functionality that I have in the C ++ library (let it name it libcppl.a ). The liblc.a library liblc.a used throughout my environment and is linked in many C projects using GCC (in C compiler mode):
>> gcc prog.c -lcl
Currently, libcl.a consists of the libcl.a object file (created using gcc from cl.c + cl.h ).
libcppl.a consists of the cppl.o object file (created using g++ from cppl.cpp + cppl.h ).
Since existing applications are written in C, and build scripts use GCC, I would like to keep the transition to the updated library as simple as possible. Thus, I want to continue to use GCC as the main compiler, but I can still contact the updated library.
Finding this answer , I could bind C ++ objects in a GCC C project with -lstdc++ :
>> gcc -c cl.c -o cl.o >> g++ -c cppl.c -o cppl.o >> ar rcs libcl.a cl.o cppl.o >> gcc prog.c -lcl -lstdc++
However, I want to eliminate the explicit mention of libstdc++ on the compilation command line .
I tried to include libstdc ++ in the cl library by doing:
>> ar rcs libcl.a cl.o cppl.o /usr/lib/libstdc++.so.6
However, when I create the application, I get:
>> gcc prog.c -lcl In file included from cppl.cpp:2: ./libcl.a(cppl.o):(.eh_frame+0x12): undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit status
1. Why doesn't the gcc linker find the standard C ++ library that was archived along with my objects?
2. Is there a restriction on using ar with libraries (as opposed to object files)?
3. Is there a way to overcome this problem?