codekiddy
codekiddy

Reputation: 6137

undefined reference to the library because of wrong Makefile syntax?

I Installed boost and created a make file that will link my static boost libraries to the main program, here is a snapshot of the Makefile that includes boost libs (please scroll down):

LIBRARY_PATH="-L/usr/lib \
         -lboost_chrono-mt \
         -lboost_date_time-mt \
         -lboost_filesystem-mt \
         -lboost_graph-mt \
         -lboost_graph_parallel-mt \
         -lboost_iostreams-mt \
         -lboost_locale-mt \
         -lboost_math_c99f-mt \
         -lboost_math_c99l-mt \
         -lboost_math_c99-mt \
         -lboost_math_tr1f-mt \
         -lboost_math_tr1l-mt \
         -lboost_math_tr1-mt \
         -lboost_mpi-mt \
         -lboost_mpi_python-mt-py26 \
         -lboost_mpi_python-mt-py27 \
         -lboost_mpi_python-mt-py32 \
         -lboost_prg_exec_monitor-mt \
         -lboost_program_options-mt \
         -lboost_python-mt-py26 \
         -lboost_python-mt-py27 \
         -lboost_python-mt-py32 \
         -lboost_random-mt \
         -lboost_regex-mt \
         -lboost_serialization-mt \
         -lboost_signals-mt \
         -lboost_system-mt \
         -lboost_test_exec_monitor-mt \
         -lboost_thread-mt \
         -lboost_timer-mt \
         -lboost_unit_test_framework-mt \
         -lboost_wave-mt \
         -lboost_wserialization-mt"
all : main
    $(CC) $(LIBRARY_PATH) $(OBJECTS) -o $(APPLICATION)

When running build there is an error saying this:

/usr/include/boost/system/error_code.hpp:214: undefined reference to `boost::system::generic_category()'

To solve the problem I moved -lboost_system-mt to the command line of the compiler like so:

all : main
    $(CC) $(LIBRARY_PATH) $(OBJECTS) -lboost_system-mt -o $(APPLICATION)

When I did that it works fine but I want my LIBRARY_PATH to be in one place and not on the command line. How do solve LIBRARY_PATH variable to make this work?

so that this will run: $(CC) $(LIBRARY_PATH) $(OBJECTS) -o $(APPLICATION)

Upvotes: 0

Views: 172

Answers (1)

Silvio Abruzzo
Silvio Abruzzo

Reputation: 33

The order of the libraries matter and in g++ libraries are read from right to left and this why the command line works. I would try to do something like

   $(CC) $(OBJECTS) $(LIBRARY_PATH)  -o $(APPLICATION)

If this is not enough try to sort the libraries in LIBRARY_PATH in such a way that libraries with less dependencies are on the right and libraries with more dependencies are on the left.

Upvotes: 1

Related Questions