How to link against boost.system with cmake

后端 未结 2 1652
日久生厌
日久生厌 2020-12-13 01:55

I use a cmake generated makefile to compile a c++ file that depends on the boost filesystem library.

During the linking process I get the following error:

相关标签:
2条回答
  • 2020-12-13 02:35

    On linux CMake figures itself that boost_filesystem is linked against boost_system. Obviously you have to tell it explicitly on Mac:

    find_package(Boost COMPONENTS system filesystem REQUIRED)
    #...
    target_link_libraries(mytarget 
      ${Boost_FILESYSTEM_LIBRARY}
      ${Boost_SYSTEM_LIBRARY}
    )
    
    0 讨论(0)
  • 2020-12-13 02:41

    This is not an "answer" to the posted question, but an observation on my Ubuntu box.

    To use the Boost libs, you have to explicitly write something like this:

    find_package(Boost COMPONENTS regex system filesystem REQUIRED)
    

    In addition, you need to link it this way:

    target_link_libraries(binary
      ${Boost_FILESYSTEM_LIBRARY}
      ${Boost_SYSTEM_LIBRARY}
      ${Boost_REGEX_LIBRARY}
    )
    

    and the following way didn't work, at least for me:

    target_link_libraries(binary regex system filesystem)
    

    This follows what Maik says, but not only on Mac.

    0 讨论(0)
提交回复
热议问题