【发布时间】:2016-08-04 19:07:41
【问题描述】:
我尝试导入 Boost 1.61.0(从 SourceForge - Boost 1.61.0 下载为 .7z),但失败了。
控制台:
"D:\Program Files (x86)\JetBrains\CLion 2016.2\bin\cmake\bin\cmake.exe" --build C:\Users\Marczak\.CLion2016.2\system\cmake\generated\WsServer-e351c9f9\e351c9f9\Debug --target WsServer -- -j 4
[ 50%] Linking CXX executable WsServer.exe
CMakeFiles\WsServer.dir\build.make:96: recipe for target 'WsServer.exe' failed
CMakeFiles\Makefile2:66: recipe for target 'CMakeFiles/WsServer.dir/all' failed
CMakeFiles\WsServer.dir/objects.a(main.cpp.obj): In function `_static_initialization_and_destruction_0':
C:/Users/Marczak/boost_1_61_0/boost/system/error_code.hpp:221: undefined reference to `boost::system::generic_category()'
C:/Users/Marczak/boost_1_61_0/boost/system/error_code.hpp:222: undefined reference to `boost::system::generic_category()'
C:/Users/Marczak/boost_1_61_0/boost/system/error_code.hpp:223: undefined reference to `boost::system::system_category()'
collect2.exe: error: ld returned 1 exit status
mingw32-make.exe[3]: *** [WsServer.exe] Error 1
mingw32-make.exe[2]: *** [CMakeFiles/WsServer.dir/all] Error 2
mingw32-make.exe[1]: *** [CMakeFiles/WsServer.dir/rule] Error 2
CMakeFiles\Makefile2:78: recipe for target 'CMakeFiles/WsServer.dir/rule' failed
mingw32-make.exe: *** [WsServer] Error 2
Makefile:117: recipe for target 'WsServer' failed
CMakeLists.txt:
cmake_minimum_required(VERSION 3.5)
project(WsServer)
set(BOOST_ROOT "C:/Users/Marczak/boost_1_61_0")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
set(SOURCE_FILES src/main.cpp)
find_package(Boost)
include_directories(${Boost_INCLUDE_DIRS})
add_executable(WsServer ${SOURCE_FILES})
如果我这样做find_package(Boost 1.61.0 COMPONENTS system filesystem REQUIRED),我会得到:
Error: Unable to find the requested Boost libraries.
Boost version: 1.61.0
Boost include path: C:/Users/Marczak/boost_1_61_0
Could not find the following static Boost libraries:
boost_system boost_filesystem
No Boost libraries were found. You may need to set BOOST_LIBRARYDIR to the directory containing Boost libraries or BOOST_ROOT to the location of Boost.
我尝试设置Boost_USE_STATIC_LIBRARIES,但也失败了。我使用 CLion 2016.2。
更新:我也尝试过旧版本。同样的错误。 .7z 里面有什么:
在其他主题中,我看到了lib 文件夹。但在这里我看不到它。我应该在BOOST_LIBRARYDIR 中输入什么?
更新 2: 从 https://sourceforge.net/projects/boost/files/boost-binaries/1.61.0/ 安装二进制文件。我注意到有一个新文件夹:lib64-msvc-14.0。它包含许多 .dll 和 .lib 文件,例如boost_atomic-vc140-mt-1_61.dll.
Boost.org 说:
如果您打算在 Windows 命令提示符下使用您的工具,那么您来对地方了。如果您计划从 Cygwin bash shell 构建,那么您实际上是在 POSIX 平台上运行的,并且应该遵循开始使用 Unix 变体的说明。其他命令 shell,例如 MinGW 的 MSYS,不受支持——它们可能工作也可能不工作。
我会尝试使用 Cygwin。
【问题讨论】:
-
您是否使用您在这里使用的任何编译器编译了 boost?听起来你刚刚在
C:/Users/Marczak/boost_1_61_0提取了源代码 -
@drescherjm 不,我是 C++ 新手。怎么编译?
-
也许 mingw 的 boost 二进制下载对你来说会更好。话虽如此,我不确定
CLion在 Windows 下使用的是什么编译器/工具包。是mingw/gcc吗?? -
@drescherjm 是的。
-
@SzymonMarczak 您可能想要添加 clion 和 mingw 标签,因为它们非常集中地描述了您的问题,不是吗?