【发布时间】:2017-07-12 01:19:04
【问题描述】:
重现我的问题...我download Boost,然后我运行booststrap 和b2 --build-dir=C:\Users\xxx\Downloads\my_boost_build_dir --prefix=C:\Users\xxx\Downloads\my_boost_install_dir --layout=system variant=release link=static install。到目前为止,一切似乎都很好。提供的前缀(安装)目录填充有headers 和libs。
但这就是事情开始出错的地方。如果我写下面的cmake文件...
find_package(Boost REQUIRED)
message("Boost_FOUND" ${Boost_FOUND})
message("Boost_INCLUDE_DIRS" ${Boost_INCLUDE_DIRS})
message("Boost_LIBRARY_DIRS" ${Boost_LIBRARY_DIRS})
message("Boost_LIBRARIES" ${Boost_LIBRARIES})
message("Boost_CHRONO_FOUND" ${Boost_CHRONO_FOUND})
message("Boost_CHRONO_LIBRARY" ${Boost_CHRONO_LIBRARY})
add_executable(main main.cpp)
target_link_libraries(main PRIVATE Boost::boost Boost::chrono)
...我用 boost install dir cmake .. -DCMAKE_PREFIX_PATH=C:\Users\xxx\Downloads\my_boost_install_dir 的路径配置它,然后我得到以下输出和错误...
Boost_FOUND1
Boost_INCLUDE_DIRSC:/Users/xxx/Downloads/my_boost_install_dir/include
Boost_LIBRARY_DIRSC:/Users/xxx/Downloads/my_boost_install_dir/lib
Boost_LIBRARIES
Boost_CHRONO_FOUND
Boost_CHRONO_LIBRARY
-- Configuring done
CMake Error at CMakeLists.txt:14 (add_executable):
Target "main" links to target "Boost::chrono" but the target was not found.
Perhaps a find_package() call is missing for an IMPORTED target, or an
ALIAS target is missing?
找到了 Boost,找到了 include 和 lib 目录,但没有找到 chrono 库(和所有其他库)。也许我需要明确命名我的组件?所以我尝试了这个 cmake...
find_package(Boost REQUIRED COMPONENTS chrono)
message("Boost_FOUND" ${Boost_FOUND})
message("Boost_INCLUDE_DIRS" ${Boost_INCLUDE_DIRS})
message("Boost_LIBRARY_DIRS" ${Boost_LIBRARY_DIRS})
message("Boost_LIBRARIES" ${Boost_LIBRARIES})
message("Boost_CHRONO_FOUND" ${Boost_CHRONO_FOUND})
message("Boost_CHRONO_LIBRARY" ${Boost_CHRONO_LIBRARY})
add_executable(main main.cpp)
target_link_libraries(main PRIVATE Boost::boost Boost::chrono)
但这会产生以下输出和错误。
CMake Error at C:/Program Files/CMake/share/cmake-3.9/Modules/FindBoost.cmake:1877 (message):
Unable to find the requested Boost libraries.
Boost version: 1.64.0
Boost include path: C:/Users/xxx/Downloads/my_boost_install_dir/include
Could not find the following Boost libraries:
boost_chrono
Some (but not all) of the required Boost libraries were found. You may
need to install these additional Boost libraries. Alternatively, set
BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT
to the location of Boost.
Call Stack (most recent call first):
CMakeLists.txt:5 (find_package)
Boost_FOUND0
Boost_INCLUDE_DIRSC:/Users/xxx/Downloads/my_boost_install_dir/include
Boost_LIBRARY_DIRS
Boost_LIBRARIES
Boost_CHRONO_FOUND
Boost_CHRONO_LIBRARY
和以前一样,它找到了 boost 和标头,但由于某种原因它找不到库。
【问题讨论】:
-
如果您需要 Boost 的
chrono组件,请在find_package调用中指定它:find_package(Boost REQUIRED chrono)。请清理问题:由于之前的问题已经解决,只需删除与其对应的文本(除非需要它来描述当前问题)。 Stack Overflow 为所有想查看帖子以前内容的人维护编辑历史记录。 -
@Tsyvarev 我清理了问题并尝试列出组件,但这并没有解决问题。 :-/
-
嗯,因为你有
.lib文件,你可能需要在find_package()之前将Boost_USE_STATIC_LIBS设置为ON。 -
@Tsyvarev 是的!显然这就是秘诀。