nitrnitr
nitrnitr

Reputation: 488

Failed at linking C++ [undefined reference boost::filesystem3 ... ]

I'm having some trouble compiling my work, I'm using Ubuntu with g++. I get a lot of these messages:

undefined reference to `boost::filesystem3::directory_entry::m_get_status(boost::system::error_code*) const'
undefined reference to `boost::filesystem3::path::extension() const'
undefined reference to `boost::filesystem3::path::filename() const'
undefined reference to `boost::filesystem3::path::filename() const'

(etc...)

I've searched and found many answers but none of those work for me.

-lboost_system (/usr/lib/gcc/i686-linux-gnu/4.4.5/../../../../lib/libboost_system.so)
-lboost_filesystem (/usr/lib/gcc/i686-linux-gnu/4.4.5/../../../../lib/libboost_filesystem.so)

When linking it shows those two libraries, I'm guessing the error is related to the second one.

hax@lap:~$ locate libboost_filesystem.so
/home/hax/boost_1_47_0/bin.v2/libs/filesystem/build/gcc-4.4.5/release/threading-multi/libboost_filesystem.so.1.47.0
/home/hax/boost_1_47_0/stage/lib/libboost_filesystem.so
/home/hax/boost_1_47_0/stage/lib/libboost_filesystem.so.1.47.0
/usr/lib/libboost_filesystem.so
/usr/lib/libboost_filesystem.so.1.42.0
/usr/local/lib/libboost_filesystem.so
/usr/local/lib/libboost_filesystem.so.1.47.0

This is the related line on my makefile:

-L. -L../bncsutil/src/bncsutil/ -L../StormLib/stormlib/ -L../boost/lib/ -lbncsutil -lpthread -ldl -lz -lStorm -lmysqlclient_r -lboost_date_time -lboost_thread -lboost_system -lboost_filesystem  -Wl -t

I tried pointing with -L several different places where I saw filesystem.so was located but it didn't work!

Can anyone see the problem in those lines? If you need me to put some extra data I'll do it, I'm not seeing the problem :(

Upvotes: 2

Views: 4230

Answers (2)

vitakot
vitakot

Reputation: 3844

Nick Betcher is right. You are mixing two versions of boost::filesystem binaries. By default, boost 1.42 is building with version 2 and Boost 1.47 with version 3.

Alternatively you can define a macro BOOST_FILESYSTEM_VERSION 2; it disables features of version 3 and the linker errors dismiss.

Upvotes: 1

Nick Betcher
Nick Betcher

Reputation: 2046

It almost looks like it's trying to link to the 1.42.0 version which may not contain those symbols. You could remove the 1.42.0 version, run ldconfig, and try your luck again.

Upvotes: 2

Related Questions