JosiP
JosiP

Reputation: 3079

Linking static c++ library into c library

I've written some code (static library) in c++, with (i think so, C compatiblity - got 'extern C' and so on), and then i wanted to use it in my C application.

When im runing my C app, i got error:

undefined symbol: _ZTISt9exception

c++ code was compiled with gcc with : -std=c++0x -lstdc++ flags

then, on obj files i run ar

i suppose that symbol comes direct from c++ library. When im compiling my C app I of course add my C++ lib in my makefile, and compilation finishes with no error.

What might be wrong ?

thx for all help

Upvotes: 1

Views: 999

Answers (2)

Some programmer dude
Some programmer dude

Reputation: 409176

A static library is not linked, it is just a collection of object files in an archive. All files names like libxxx.a are static libraries, while files named like libyyy.so are dynamic libraries.

This means that the the external symbols in your library are never resolved until you link with it to make an executable. Then you need all the library files needed by your library as well.

Upvotes: 1

trojanfoe
trojanfoe

Reputation: 122391

You'll need to link the final executable with the C++ runtime library (-lstdc++); it has no effect when compiling the C++ objects, only linking the executable.

Upvotes: 1

Related Questions