0

I am trying to build a project on Windows using MinGW and CMake that uses the Boost library v1.60.0. I was able to successfully build Boost with MinGW with the following:

cd <boost_root>\tools\build
bootstrap.bat gcc
cd ..\..
tools\build\b2.exe --prefix=<boost_install_root> toolset=gcc link=static

Now when I build my application via CMake I do it like this:

add_executable(myApp ... .cpp sources ...)
target_include_directories(myApp <myApp include directory> ${Boost_INCLUDE_DIRS})
target_link_libraries(myApp ${Boost_LIBRARIES})

and I get several errors all almost identical to:

<boost_install_root>/lib/libboost_timer-mgw53-mt-1_60.a(cpu_timer.o):cpu_ timer.cpp:(.text+0x25a): undefined reference to `boost::chrono::steady_clock::now()'

The libraries are all there and are visible from within CMake from what I can tell, so what am I missing?

MrJman006
  • 752
  • 10
  • 26
  • Is the chrono library in your list of Boost components, i.e. `find_package(Boost 1.60.0 REQUIRED COMPONENTS chrono)`? – utopia Aug 02 '17 at 22:39
  • yes, I use this `find_packages(Boost 1.60.0 REQUIRED COMPONENTS filesystem system thread date_time regex chrono timer OPTIONAL_COMPONENTS log log_setup` – MrJman006 Aug 02 '17 at 22:47
  • Is your CMake recent enough? – usr1234567 Aug 02 '17 at 22:47
  • I have CMake v3.8.1 – MrJman006 Aug 02 '17 at 22:49
  • Do you have `set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_MULTITHREADED ON)` somewhere in your applications CMakeLists.txt? – vre Aug 03 '17 at 09:27
  • I do have those two set – MrJman006 Aug 03 '17 at 14:00
  • Can you change the order of the libraries you provide to the linker? I mean referencing `timer` before `chrono` in the `find_package` call. – vre Aug 03 '17 at 14:28
  • @vre I really did not expect that to work, but sure enough that makes the build happy. Is there some documentation somewhere I am not aware of that discusses this? I just double checked CMake's documentation and they make it sound like there is no ordering when finding components of a package. If you can work up an answer for this, I'll mark it as correct. – MrJman006 Aug 03 '17 at 14:43

1 Answers1

0

Reformatting my previous comment to an answer:

For the linking to work properly the order of the libraries is important. Because the Boost timer library depends on features of the chrono library, you need to reorder the libraries in your find_package call.

I am not aware of a web page that gives you all the inter dependencies of the Boost libraries, but bcp might be a starting point.

vre
  • 6,041
  • 1
  • 25
  • 39