2

I have been struggling to compile and link a C++ application that uses Boost libraries under a Ubuntu Server 11.01 64-bit edition. At first not suceeding with prepackaged Boost libraries, I decided to compile it on my own. Boost compiles with no problem, but when I try to compile an application, linker starts spewing out errors as though no libraries were included.

builtinFunctions.o: In function `__static_initialization_and_destruction_0(int, int)':
builtinFunctions.cpp:(.text+0xcaab): undefined reference to `boost::system::generic_category()'
builtinFunctions.cpp:(.text+0xcab7): undefined reference to `boost::system::generic_category()'
builtinFunctions.cpp:(.text+0xcac3): undefined reference to `boost::system::system_category()'
builtinFunctions.o: In function `boost::system::error_code::error_code()':
builtinFunctions.cpp:(.text._ZN5boost6system10error_codeC2Ev[_ZN5boost6system10error_codeC5Ev]+0x17): undefined reference to `boost::system::system_category()'
builtinFunctions.o: In function `boost::filesystem3::exists(boost::filesystem3::path const&)':
...

This is a Makefile that I use:

CC=g++
CFLAGS=-std=c++0x -c -Wall -I . -I ./boost_1_48_0/ -DBOOST_THREAD_USE_LIB

all: project

project: builtinFunctions.o main.o operators.o conversionUtils.o
        $(CC)   -L./boost_1_48_0/stage/lib/ \
                -lpthread -lboost_date_time-gcc46-mt-s-1_48 -lboost_program_options-gcc46-mt-s-1_48 \
                -lboost_filesystem-gcc46-mt-s-1_48 -lboost_system-gcc46-mt-s-1_48 builtinFunctions.o \
                main.o operators.o conversionUtils.o -o project

main.o: main.cpp
        $(CC) $(CFLAGS) main.cpp

operators.o: operators.cpp
        $(CC) $(CFLAGS) operators.cpp

conversionUtils.o: conversionUtils.cpp
        $(CC) $(CFLAGS) conversionUtils.cpp

builtinFunctions.o: builtinFunctions.cpp
        $(CC) $(CFLAGS) builtinFunctions.cpp

clean:
        rm -rf *o project

Anything else I could try besides an earlier version of GCC? Thank you.

  • GCC version is `gcc version 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3)` –  Dec 05 '11 at 01:27
  • 6
    Libraries always come at the *end*, after all the objects... – Kerrek SB Dec 05 '11 at 01:29
  • 1
    Kerrek you should post an answer so Tibor can mark it as the answer to this question. Tibor - you should revise your question to indicate that this is a general linking problem. – Will Bickford Dec 05 '11 at 02:25
  • How exactly am I to revise a question? Thank you for advice. –  Dec 05 '11 at 14:31

1 Answers1

4

The order of libraries on link line matters, and yours is wrong.

Employed Russian
  • 199,314
  • 34
  • 295
  • 362