문제

I'm using OSX Mountain Lion. I just downloaded, unpacked, and built boost 1.52.0 using the instructions supplied from the boost website: http://www.boost.org/doc/libs/1_52_0/more/getting_started/unix-variants.html. I left the default installation prefix at /usr/local, meaning that the libraries are installed in /usr/local/lib and the header files are in /usr/local/include. I have verified that the libraries and headers are present there and recently modified.

I'm attempting to compile the boost asynchronous I/O example found here: http://www.boost.org/doc/libs/1_52_0/doc/html/boost_asio/tutorial/tuttimer5/src.html (source).

Here is my compilation command:

g++ -Wall -c -g -I/usr/local/include src/test1.cpp -o src/test1.o

where src/test1.cpp is the example source file. Here is my linking command (and error):

g++ -Wall -L/usr/local/lib -lboost_thread -lboost_system  src/test1.o -o bin/test1
Undefined symbols for architecture x86_64:
  "boost::thread::~thread()", referenced from:
      _main in test1.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

I have tried using both Apple's clang++ 4.0 and g++ 4.6.0. I get the same undefined symbol error from both programs.

Other people seem to have had trouble compiling this code sample as well. I am aware of this question: C++ / Boost: Undefined Symbols in example? and this one: Linker error when compiling boost.asio example. However, each of these problems seems to have been fixed by adding the appropriate switches (-lboost_thread and -lboost_system) to the command line. I already have those. I have also tried adding -lpthread without luck.

Thank you for taking time to look at my question! Any help is appreciated. :)

도움이 되었습니까?

해결책

Just ran into this same problem, and I found that reverting to Boost 1.49 fixes the problem. Download links for Boost 1.49 are here:

http://www.boost.org/users/history/version_1_49_0.html

Before installing 1.49, I removed 1.52 by deleting /usr/local/include/boost and /usr/local/lib/*boost*. Not sure what changed between 1.49 and 1.52 to cause this problem, or whether Boost 1.50 or 1.51 will work.

다른 팁

Put the libraries you link with last on the command line.

The GNU linker uses kind of reverse lookup of dependencies, so if file A depends on library B, B should come after A on the command line.

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