【发布时间】:2016-09-09 06:52:17
【问题描述】:
一个月后回到项目后,我能够成功运行 CMake,并显示以下输出
-- Boost version: 1.61.0
-- Found the following Boost libraries:
-- system
-- thread
-- filesystem
-- chrono
-- date_time
-- atomic
-- Configuring done
-- Generating done
-- Build files have been written to: /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
我做了一些研究,发现其他人也有同样的问题,因为没有为那里的架构(64 位和 32 位)链接正确版本的库,但我不确定如何确定这是否是我的问题。
这是我未更改的 CMakeLists.txt 文件
CMAKE_MINIMUM_REQUIRED(VERSION 3.4.1)
PROJECT(MangaMeCLI)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
INCLUDE_DIRECTORIES(includes)
ADD_EXECUTABLE(mangaMeCLI src/mangaMeCLI.cpp)
MESSAGE("${CMAKE_CXX_FLAGS}")
SET(Boost_USE_MULTITHREADED ON)
FIND_PACKAGE(Boost REQUIRED COMPONENTS system thread filesystem)
INCLUDE_DIRECTORIES(${BOOST_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(mangaMeCLI ${BOOST_LIBRARIES})
SET(OPENSSL_ROOT_DIR /usr/local/Cellar/openssl/*)
FIND_PACKAGE(OpenSSL REQUIRED)
INCLUDE_DIRECTORIES(${OPENSSL_INCLUDE_DIR})
TARGET_LINK_LIBRARIES(mangaMeCLI ${OPENSSL_LIBRARIES})
FIND_PACKAGE(cppnetlib REQUIRED)
INCLUDE_DIRECTORIES(${CPPNETLIB_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(mangaMeCLI ${CPPNETLIB_LIBRARIES})
在阅读了一条有用的评论后,我发现 BOOST_LIBRARIES 变量为空,即使 cmake 打印它找到了我正在寻找的 boost 库。我假设这是我的错误的原因。
【问题讨论】:
-
...(64bit vs 32bit) but am not sure how to identify if this is the issue for me.- CMake 找到的库存储在BOOST_LIBRARIES变量中。您可以添加行message(${BOOST_LIBRARIES})作为该变量的输出值(在cmake阶段),并检查库。 -
此外,您可以在调用
find_package(Boost...)之前尝试set(Boost_DEBUG ON)以启用FindBoost 的调试输出。 -
打开调试后,我多次发现此 NO_DEFAULT_PATH;NO_CMAKE_FIND_ROOT_PATH,感谢您的帮助,我将对此进行调查,看看这是否是我的错误编辑的原因:调查后似乎是好的,因为我没有指定根路径