Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

G++ can't find boost libraries. I say they're in plain sight

I'm trying to build some code. Here is the error I'm getting:

main.o: In function `__static_initialization_and_destruction_0':
/home/jmbeck/Downloads/boost_1_48_0/boost/system/error_code.hpp:214: undefined reference to `boost::system::generic_category()'

There is more, but I don't think it's relevant.

Here is the build command:

g++ -I/home/jmbeck/Downloads/boost_1_48_0 
    -L/home/jmbeck/Downloads/boost_1_48_0/stage/lib 
    -lm 
    -lboost_system 
    -lboost_thread
    -lboost_regex 
    main.cpp

The /home/jmbeck/Downloads/boost_1_48_0/stage/lib directory contains the expected files:

libboost_system.a
libboost_system.so@
libboost_system.so.1.48.0*
libboost_thread.a
libboost_thread.so@
libboost_thread.so.1.48.0* 
libboost_regex.a
libboost_regex.so@
libboost_regex.so.1.48.0*
... etc...

I've tried building a quick program that didn't use the pre-compiled libraries, and it compiled just fine. It finds the appropriate headers, but not the libraries.

What am I doing wrong?

like image 582
jmbeck Avatar asked Jan 19 '12 19:01

jmbeck


1 Answers

Try putting the libraries after main.cpp.

I've experienced some weirdness in the past when GCC ignores libraries because it doesn't think they're used, before reaching my source files.

like image 181
James McLaughlin Avatar answered Sep 21 '22 02:09

James McLaughlin