Search code examples
c++boostlinkerboost-system

Undefined reference to boost::system::generic_category despite linking with boost_system


My compilation command is:

g++ -I/home/foo/boost_1_56_0 -L/home/foo/boost_1_56_0/stage/lib -lboost_system -lboost_filesystem -lpthread -lboost_thread -lboost_system -lboost_filesystem -lpthread -lboost_thread main.cpp foo.cpp

I get an undefined reference to boost::system::generic_category error despite the fact that I link it with -lboost_thread.

I also get undefined references to:

boost::system::generic_category and pthread_detach.


Solution

  • You should specify the libraries after the source file(s).

    Also, prefer -pthread over manually linking libpthread.so

    g++ -I/home/foo/boost_1_56_0 -L/home/foo/boost_1_56_0/stage/lib -pthread main.cpp foo.cpp -lboost_system -lboost_filesystem -lboost_thread