简体   繁体   中英

Error when trying to link Boost library using CMake

I'm using:

  • CMake 3.16.4
  • Visual Studio Community 2019 (Version 16.4.4)
  • Boost 1.72.00

My CMake file was based on the second example at https://cmake.org/cmake/help/v3.6/module/FindBoost.html , plus:

  • I'm debugging it:

     set (Boost_DEBUG ON) set (Boost_DETAILED_FAILURE_MSG ON) find_package(Boost 1.72 EXACT REQUIRED COMPONENTS filesystem)
  • I had to set:

     target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${Boost_INCLUDE_DIR})
  • And I'm using Boost_LIBRARIES variable:

     target_link_libraries(${CMAKE_PROJECT_NAME} Qt5::Widgets ${Boost_LIBRARIES})

All that should just work like a charm - but I'm getting:

2>LINK : fatal error LNK1104: cannot open file 'libboost_filesystem-vc142-mt-gd-x64-1_72.lib'

From FindBoost debug I can see that:

[ C:/Program Files/CMake/share/cmake-3.16/Modules/FindBoost.cmake:1541 ] BOOST_LIBRARYDIR = < unset>

THIS SOLVES THE ISSUE:

link_directories(${Boost_LIBRARY_DIR_RELEASE})

THIS ALSO SOLVES THE ISSUE:

set(Boost_USE_STATIC_LIBS        ON) # only find static libs
set(Boost_USE_MULTITHREADED      ON)
set(Boost_USE_STATIC_RUNTIME    OFF)

BUT I'M NOT SUPPOSED TO NEED THAT!

Can someone tell what is wrong?

I'm using:

  • CMake 3.16.4
  • Visual Studio Community 2019 (Version 16.4.4)
  • Boost 1.72.00

My CMake file was based on the second example at https://cmake.org/cmake/help/v3.6/module/FindBoost.html , plus:

  • I'm debugging it:

     set (Boost_DEBUG ON) set (Boost_DETAILED_FAILURE_MSG ON) find_package(Boost 1.72 EXACT REQUIRED COMPONENTS filesystem)
  • I had to set:

     target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${Boost_INCLUDE_DIR})
  • And I'm using Boost_LIBRARIES variable:

     target_link_libraries(${CMAKE_PROJECT_NAME} Qt5::Widgets ${Boost_LIBRARIES})

All that should just work like a charm - but I'm getting:

2>LINK : fatal error LNK1104: cannot open file 'libboost_filesystem-vc142-mt-gd-x64-1_72.lib'

From FindBoost debug I can see that:

[ C:/Program Files/CMake/share/cmake-3.16/Modules/FindBoost.cmake:1541 ] BOOST_LIBRARYDIR = < unset>

THIS SOLVES THE ISSUE:

link_directories(${Boost_LIBRARY_DIR_RELEASE})

THIS ALSO SOLVES THE ISSUE:

set(Boost_USE_STATIC_LIBS        ON) # only find static libs
set(Boost_USE_MULTITHREADED      ON)
set(Boost_USE_STATIC_RUNTIME    OFF)

BUT I'M NOT SUPPOSED TO NEED THAT!

Can someone tell what is wrong?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM