【发布时间】:2020-09-21 13:16:59
【问题描述】:
我无法在 GCC-6 中构建一个简单的 Hello World 程序,但它与 Clion 中的 Clang 可以正常工作。
现在我尝试在此处构建和运行 Boost Date Time 的第一个示例
我的 CMake 看起来像
cmake_minimum_required(VERSION 3.16)
project(Boost_Run_2)
set(CMAKE_CXX_STANDARD 11)
find_package(Boost REQUIRED COMPONENTS date_time)
add_executable(Boost_Run_2 main.cpp)
target_link_libraries(Boost_Run_2 PRIVATE Boost::date_time)
但它会引发链接器错误
====================[ Build | Boost_Run_2 | Debug ]=============================
/Applications/CLion.app/Contents/bin/cmake/mac/bin/cmake --build /Users/alihasan/Documents/GSOC/Boost_Run_2/cmake-build-debug --target Boost_Run_2 -- -j 4
Scanning dependencies of target Boost_Run_2
[ 50%] Building CXX object CMakeFiles/Boost_Run_2.dir/main.cpp.o
[100%] Linking CXX executable Boost_Run_2
Undefined symbols for architecture x86_64:
"boost::gregorian::greg_month::get_month_map_ptr[abi:cxx11]()", referenced from:
unsigned short boost::date_time::month_str_to_ushort<boost::gregorian::greg_month>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) in main.cpp.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
make[3]: *** [Boost_Run_2] Error 1
make[2]: *** [CMakeFiles/Boost_Run_2.dir/all] Error 2
make[1]: *** [CMakeFiles/Boost_Run_2.dir/rule] Error 2
make: *** [Boost_Run_2] Error 2
当我使用 Clang 运行相同的程序时,我能够运行它。没有链接器错误。所以我假设我的 Boost 库设置正确。
我希望能够使用 GCC-6/G++-6 运行相同的程序。
我有一个 macOS Mojave 10.14.3,我使用 brew install boost 来安装 Boost 库。
【问题讨论】:
-
C++ 编译器被称为
g++-6,而不是gcc-6。 -
@HolyBlackCat 非常感谢。这很愚蠢。有效。我会更新我的问题。现在我不必指定链接器来构建 C++ 标准文件。但是,Boost 代码仍然出错。我认为我在设置 Boost 库时没有问题,因为它与 Clang 配合得很好。