Cmake FindBoost.cmake MinGW-W64:搜索名称不正确的库 [英] Cmake FindBoost.cmake MinGW-W64: searching for library with incorrect name
问题描述
我已经构建了Boost 1.68(使用 https://gist.github.com/sim642/29caef3cc8afaa273ce6 ,并在b2命令行中添加 link = static,shared
来构建共享库.)
I have built Boost 1.68 (using instructions from https://gist.github.com/sim642/29caef3cc8afaa273ce6, and adding link=static,shared
to the b2 command line to also build shared libraries.)
库似乎正确构建,并且我已经正确设置了 BOOST_INCLUDEDIR
和 BOOST_LIBRARYDIR
环境变量.
The libraries appear to build correctly, and I have set the BOOST_INCLUDEDIR
and BOOST_LIBRARYDIR
environment variables correctly.
但是,当我将以下内容添加到 CMakeLists.txt
时:
However, when I add the following to a CMakeLists.txt
:
find_package(Boost REQUIRED COMPONENTS system context coroutine thread random REQUIRED)
并使用 MinGW Makefiles
生成时,出现以下错误:
and generate with MinGW Makefiles
, I get the following error:
CMake Error at C:/Users/pbelanger/AppData/Local/JetBrains/Toolbox/apps/CLion/ch-0/182.4129.15/bin/cmake/win/share/cmake-3.12/Modules/FindBoost.cmake:2044 (message):
Unable to find the requested Boost libraries.
Boost version: 1.68.0
Boost include path: C:/boost/install/include/boost-1_68
Could not find the following static Boost libraries:
boost_system
boost_context
boost_coroutine
boost_thread
boost_random
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.
我将在 find_package
行之前的位置添加了添加 set(Boost_DEBUG ON)
的输出: https://pastebin.com/yRd5DPt4
I have placed the output of adding set(Boost_DEBUG ON)
before the find_package
line here: https://pastebin.com/yRd5DPt4
根据调试输出,查找脚本正在正确的目录( c:\ boost \ install \ lib
)中进行搜索,但未找到Boost库,因为它们具有不同的命名方案.例如, system
库的名称为 libboost_system-mgw81-mt-x64-1_68.dll
,但是查找脚本正在传递库名 boost_system-mgw81-mt-1_68
到CMake的 find_library
.请注意,寻址模型( -x64
)没有在后一个名称中列出.
According to the debug output, the find script is searching in the correct directory (c:\boost\install\lib
), but is not finding the boost libraries since they have a different naming scheme. For example, the system
library is named libboost_system-mgw81-mt-x64-1_68.dll
, but the find script is passing he library name boost_system-mgw81-mt-1_68
to CMake's find_library
. Notice that the addressing model (-x64
)is not listed in the latter name.
我的问题是,这是否与Boost或findCMake脚本有关?是否可以通过在findCMake脚本之前设置特定的cmake变量来解决此问题?
My question is whether this is an issue with Boost, or the findCMake script? Can this be fixed by setting a specific cmake variable before the findCMake script?
推荐答案
Looking at the source of FindBoost.cmake
, line 1478,
the script looks at the value of CMAKE_CXX_COMPILER_ARCHITECTURE_ID
in order
to build the correct architecture tag. However, on my compiler (MinGW-W64 8.1
64-bit), this string is empty. Therefore, the architecture tag is omitted.
我必须通过将以下内容手动设置此变量的值在我的 find_package
行之前:
I have to set the value of this variable manually by putting the following
before my find_package
line:
if(WIN32 AND "x${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}" STREQUAL "x")
message(WARNING "WIN32 compiler does not specify CMAKE_CXX_COMPILER_ARCHITECTURE_ID -- filling in manually")
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
set(CMAKE_CXX_COMPILER_ARCHITECTURE_ID "x64")
else()
set(CMAKE_CXX_COMPILER_ARCHITECTURE_ID "x86")
endif()
message(STATUS "Compiler architecture: ${CMAKE_CXX_COMPILER_ARCHITECTURE_ID}")
endif()
# now we should be able to find boost correctly.
find_package(Boost REQUIRED COMPONENTS system context coroutine thread random REQUIRED)
这使find_package正常工作.
This makes the find_package work correctly.
这篇关于Cmake FindBoost.cmake MinGW-W64:搜索名称不正确的库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!