I am trying to compile my C++ project on Linux x64 with boost libraries 1.57.
This project is compiled with scons and I successfully compiled it on my Arch Linux, but this time failed on a Ubuntu machine.
/usr/bin/g++ -o build/gcc.release/app -pthread -g
-lpthread -lz -lboost_coroutine -lboost_context -lboost_date_time
build/gcc.release/src/han/unity/rpcx.o: In function `attributes':
/usr/local/include/boost/coroutine/attributes.hpp:31: undefined reference
nm /usr/local/lib/libboost_coroutine.a | grep "default_size"
0000000000000170 T _ZN5boost10coroutines12stack_traits12default_sizeEv
After several hours effort, I finally solved it.
That turns out to be the old boost (v1.55) lib still existing, which has static libraries with the same name of my manually installed boost library (v1.57). The linker found the v1.55 static libs before v1.57, so it used these libs for linking. However, in the old version, the function
boost::coroutines::stack_traits::default_size() is still not introduced, which makes the linker cannot find the right location of this function, and returns "undefind reference".
For those who happens to find this questions from googling "undefined reference" errors during compiling, I got several steps about debugging this kind of problem and wrote here for your information.
Check if the library you linked with exists in
/usr/local/lib/, if not, try to install these first.
Check if you added the correct linking flag for your referred libs. For example, if you use boost_coroutine libs, be sure to add
-lboost_coroutine during linking.
Check if the order of linking flags are correct (for gcc). This could be the cause of most cases. Make sure to put B in front of A if B depends on A.
Check if different versions exists for the same libraries.
I hope these could help somehow.