C++ CMake找到boost库,但Make无法链接它们

C++ CMake找到boost库,但Make无法链接它们,c++,boost,makefile,cmake,C++,Boost,Makefile,Cmake,在一个月后回到一个项目后,我能够通过以下输出成功运行CMake [ 50%] Building CXX object CMakeFiles/mangaMeCLI.dir/src/mangaMeCLI.cpp.o [100%] Linking CXX executable mangaMeCLI Undefined symbols for architecture x86_64: "boost::filesystem::path::operator/=(char const*)", refere

在一个月后回到一个项目后,我能够通过以下输出成功运行CMake

[ 50%] Building CXX object CMakeFiles/mangaMeCLI.dir/src/mangaMeCLI.cpp.o
[100%] Linking CXX executable mangaMeCLI
Undefined symbols for architecture x86_64:
  "boost::filesystem::path::operator/=(char const*)", referenced from:
      _main in mangaMeCLI.cpp.o
  "boost::filesystem::path::operator/=(boost::filesystem::path const&)", referenced from:
      boost::filesystem::path::operator/=(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in mangaMeCLI.cpp.o
      boost::filesystem::path::operator/=(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in mangaMeCLI.cpp.o
  "boost::filesystem::detail::current_path(boost::system::error_code*)", referenced from:
      boost::filesystem::current_path() in mangaMeCLI.cpp.o
  "boost::filesystem::detail::create_directory(boost::filesystem::path const&, boost::system::error_code*)", referenced from:
      boost::filesystem::create_directory(boost::filesystem::path const&) in mangaMeCLI.cpp.o
  "boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)", referenced from:
      boost::filesystem::exists(boost::filesystem::path const&) in mangaMeCLI.cpp.o
      boost::filesystem::is_directory(boost::filesystem::path const&) in mangaMeCLI.cpp.o
  "boost::system::system_category()", referenced from:
      ___cxx_global_var_init.75 in mangaMeCLI.cpp.o
  "boost::system::generic_category()", referenced from:
      ___cxx_global_var_init.73 in mangaMeCLI.cpp.o
      ___cxx_global_var_init.74 in mangaMeCLI.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [mangaMeCLI] Error 1
make[1]: *** [CMakeFiles/mangaMeCLI.dir/all] Error 2
make: *** [all] Error 2
——Boost版本:1.61.0
--找到以下Boost库:
--系统
--线
--文件系统
--计时
--日期和时间
--原子的
--配置完成
--生成完成
--生成文件已写入:/Users/LittleNewt/gitness/MangaMeCLI/Build
但是由于某些原因,在生成的MakeFile上运行Make时,我得到了以下输出

[ 50%] Building CXX object CMakeFiles/mangaMeCLI.dir/src/mangaMeCLI.cpp.o
[100%] Linking CXX executable mangaMeCLI
Undefined symbols for architecture x86_64:
  "boost::filesystem::path::operator/=(char const*)", referenced from:
      _main in mangaMeCLI.cpp.o
  "boost::filesystem::path::operator/=(boost::filesystem::path const&)", referenced from:
      boost::filesystem::path::operator/=(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) in mangaMeCLI.cpp.o
      boost::filesystem::path::operator/=(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in mangaMeCLI.cpp.o
  "boost::filesystem::detail::current_path(boost::system::error_code*)", referenced from:
      boost::filesystem::current_path() in mangaMeCLI.cpp.o
  "boost::filesystem::detail::create_directory(boost::filesystem::path const&, boost::system::error_code*)", referenced from:
      boost::filesystem::create_directory(boost::filesystem::path const&) in mangaMeCLI.cpp.o
  "boost::filesystem::detail::status(boost::filesystem::path const&, boost::system::error_code*)", referenced from:
      boost::filesystem::exists(boost::filesystem::path const&) in mangaMeCLI.cpp.o
      boost::filesystem::is_directory(boost::filesystem::path const&) in mangaMeCLI.cpp.o
  "boost::system::system_category()", referenced from:
      ___cxx_global_var_init.75 in mangaMeCLI.cpp.o
  "boost::system::generic_category()", referenced from:
      ___cxx_global_var_init.73 in mangaMeCLI.cpp.o
      ___cxx_global_var_init.74 in mangaMeCLI.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [mangaMeCLI] Error 1
make[1]: *** [CMakeFiles/mangaMeCLI.dir/all] Error 2
make: *** [all] Error 2

在阅读了一篇有用的评论后,我发现BOOST_LIBRARIES变量是空的,即使cmake打印出它找到了我正在寻找的BOOST库。我假设这就是我出错的原因。

CMake变量区分大小写。根据,您需要的是
Boost\u库
,而不是
Boost\u库

INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(mangaMeCLI ${Boost_LIBRARIES})

…(64位vs 32位),但我不确定如何确定这是否是我的问题。
-CMake找到的库存储在
BOOST\u库中。您可以为该变量的输出值(在
cmake
阶段)添加行
消息(${BOOST\u LIBRARIES})
,并检查库。此外,您可以在调用
查找包(BOOST…)之前尝试
设置(BOOST\u DEBUG ON)
从FindBoost启用调试输出。打开调试后,我发现此无默认路径;无需多次查找根路径,感谢您的帮助,我将对此进行调查,并查看这是否是我错误编辑的原因:在调查之后,似乎没有问题,因为我没有指定一个有效的根路径,这一定是更新的CMAKE版本中的一个更改,因为资本增值过去工作正常,您是否建议我更改我的其他find_包以匹配包名的拼写,例如OpenSSL_INCLUDE_DIRS?@Jem4687是的,CMake正在努力统一find生成的变量名,以使用find模块名的确切大小写。当然,如果您可以并且模块支持它们,则最好使用具有使用要求的导入目标(这样您就不必关心包含目录等)。根据我链接的文档,Boost确实支持它们。