Search code examples
g++ldunix-ar

g++ combining libraries


So, I'm trying to incorporate the libpthread.a library into my own library. But its giving me linker problems when I try and compile the code that uses it. I compile it by doing the following:

g++ foo.cpp foo.o
ar x /usr/lib/libpthread.a
ar rcs libfoo.a *.o

g++ bar.cpp -o bar -L./ -lfoo

But I end up with a bunch of undefined reference to 'pthread_stuff'

I really don't understand what I'm doing wrong.


Solution

  • So I fixed it by changing the compile arguments to:

    g++ -static bar.cpp -o bar -L./ -lfoo