Dean Chen
Dean Chen

Reputation: 3890

MongoDB 2.4 C++ driver causes link error

I downloaded the newest codes from http://dl.mongodb.org/dl/cxx-driver and compiled it as a static library on Ubuntu 12.04 & 12.10. My GCC is 4.7, and using CMake as a build system. Boost library: 1.48 on Ubuntu 12.04, 1.49 on Ubuntu 12.10.

Then, my two projects compiled successfully with mongodb client library, but the third project got link error below:

Linking CXX executable cml_cloud

/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../lib/libmongoclient.a(log.o): In function mongo::LoggingManager::start(std::string const&, bool)': log.cpp:(.text._ZN5mongo14LoggingManager5startERKSsb[_ZN5mongo14LoggingManager5startERKSsb]+0x4c): undefined reference toboost::filesystem3::detail::status(boost::filesystem3::path const&, boost::system::error_code*)' log.cpp:(.text._ZN5mongo14LoggingManager5startERKSsb[_ZN5mongo14LoggingManager5startERKSsb]+0x86): undefined reference to boost::filesystem3::detail::status(boost::filesystem3::path const&, boost::system::error_code*)' log.cpp:(.text._ZN5mongo14LoggingManager5startERKSsb[_ZN5mongo14LoggingManager5startERKSsb]+0xb8): undefined reference toboost::filesystem3::detail::status(boost::filesystem3::path const&, boost::system::error_code*)' collect2: error: ld returned 1 exit status make[2]: * [bin/cml_cloud] Error 1 make[1]: * [bin/CMakeFiles/cml_cloud.dir/all] Error 2 make: * [all] Error 2

I never ran into this kind of problem before. How to solve it?

Upvotes: 0

Views: 904

Answers (1)

Dean Chen
Dean Chen

Reputation: 3890

I fixed it. That's nothing to do with mongodb library, I just changed the order of target_link_libraries in CMakeLists.txt.

The original statement is:

target_link_libraries( cml_cloud ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES} cppcms mongoclient booster loki cryptopp)

Now it looks like:

target_link_libraries( cml_cloud ${CMAKE_THREAD_LIBS_INIT} cppcms mongoclient booster loki cryptopp ${Boost_LIBRARIES})

I am happy now, but anybody knows why it corrects this problem?

Upvotes: 0

Related Questions