Вопрос
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.
Решение 2
So I fixed it by changing the compile arguments to:
g++ -static bar.cpp -o bar -L./ -lfoo
Другие советы
You have to declare your functions that use other C functions as extern "C"
or else C++ name mangling would "distort" your names. More info: http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/index.jsp?topic=%2Fcom.ibm.vacpp6m.doc%2Flanguage%2Fref%2Fclrc01name_mangling.htm
Не связан с StackOverflow