문제

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top