我知道已经多次询问过了,但我似乎已经正确设置了所有必需的变量,并且cmake一直没有找到所需的组件。
我成功(有奋斗......)编译了boost库,他们有这个文件结构:
C:\boost_1_57_0
| - android
| | - lib
| | - libboost_date_time-gcc-mt-s-1_57.a
| | - libboost_random-gcc-mt-s-1_57.a
| | - libboost_system-gcc-mt-s-1_57.a
| - boost
| - date_time
| | - *.hpp
| - random
| | - *.hpp
| - system
| - *.hpp
这是我的cmake的相关部分:
option(BUILD_SHARED_LIBS "Build the shared library" OFF)
option(Boost_USE_STATIC_LIBS "Use Boost static version" ON)
set(BOOST_VER "1.57.0" CACHE STRING "boost version" )
set(BOOST_ROOT "/cygdrive/c/boost_1_57_0/")
set(BOOST_INCLUDEDIR "/cygdrive/c/boost_1_57_0/boost/")
set(BOOST_LIBRARYDIR "/cygdrive/c/boost_1_57_0/android/lib/")
# I tried also C: instead of /cygdrive/c, with no success
message(STATUS "BOOST_ROOT = ${BOOST_ROOT}")
message(STATUS "BOOST_INCLUDEDIR = ${BOOST_INCLUDEDIR}")
message(STATUS "BOOST_LIBRARYDIR = ${BOOST_LIBRARYDIR}")
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost ${BOOST_VER} REQUIRED COMPONENTS system date_time random)
这是我得到的输出:
$ cmake ./
-- not define build type, set to release
-- BOOST_ROOT = /cygdrive/c/boost_1_57_0/
-- BOOST_INCLUDEDIR = /cygdrive/c/boost_1_57_0/boost/
-- BOOST_LIBRARYDIR = /cygdrive/c/boost_1_57_0/android/lib/
CMake Error at /usr/share/cmake-3.3.2/Modules/FindBoost.cmake:1245 (message):
Unable to find the requested Boost libraries.
Boost version: 1.57.0
Boost include path: /cygdrive/c/boost_1_57_0
Could not find the following static Boost libraries:
boost_system
boost_date_time
boost_random
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.
Call Stack (most recent call first):
CMakeLists.txt:32 (find_package)
为什么不起作用?为什么我将BOOST_INCLUDEDIR
设置为/cygdrive/c/boost_1_57_0/boost/
,但他似乎忽略了它并在whatever I set BOOST_ROOT to
中查找包含文件?为什么他也忽略了BOOST_LIBRARYDIR
?
答案 0 :(得分:0)
好的,我找到了问题的原因。 首先,我必须
set(Boost_DEBUG 1)
在我的CMakeLists.txt中,以便find_package(Boost ${BOOST_VER} ... )
调用的FindBoost.cmake可以打印出他正在搜索的内容。
所以我发现问题在于:
-- [ /usr/share/cmake-3.3.2/Modules/FindBoost.cmake:827 ] guessed _boost_COMPILER = -gcc46
虽然应该是-gcc
,但是:
-- [ /usr/share/cmake-3.3.2/Modules/FindBoost.cmake:1052 ] Searching for SYSTEM_LIBRARY_RELEASE: boost_system-gcc46-mt-1_57
所以我发现变量Boost_LIB_PREFIX
没有设置。
第一个问题是由FindBoost.cmake中的_Boost_GUESS_COMPILER_PREFIX
函数引起的。出于某种原因,我有这些变量:
CMAKE_CXX_COMPILER_ID : GNU #why?? I'm using Cygwin under Windows...
MINGW : #unset
UNIX : 1
CMAKE_COMPILER_IS_GNUCXX : 1
Boost_MAJOR_VERSION : 1
Boost_MINOR_VERSION : 57
所以在某一点上:
if(${Boost_MAJOR_VERSION}.${Boost_MINOR_VERSION} VERSION_LESS 1.34)
set(_boost_COMPILER "-gcc") # no GCC version encoding prior to 1.34
else()
....
set(_boost_COMPILER "-gcc${_boost_COMPILER_VERSION}")
endif()
第二个问题是由于FindBoost.cmake中的这些行:
set(Boost_LIB_PREFIX "")
if ( (GHSMULTI AND Boost_USE_STATIC_LIBS) OR
(WIN32 AND Boost_USE_STATIC_LIBS AND NOT CYGWIN) )
set(Boost_LIB_PREFIX "lib")
endif()
我仍然不明白为什么它不应该添加前缀" lib"与cygwin。
最终,我并不确切地知道他为什么要搜索错误的库名,也许我搞砸了并使用不同的工具/版本进行编译。