gpt4 book ai didi

c++ - CMake 在使用 android-cmake 工具链文件时找不到 Boost 库

转载 作者:可可西里 更新时间:2023-11-01 16:35:39 32 4
gpt4 key购买 nike

我正在尝试为使用 Boost 库的代码创建一个 CMake 项目。我想为 Android 构建它,我正在使用这个项目作为引用:https://code.google.com/p/android-cmake/ .

我想使用我之前为 android 构建的 Boost 静态库,而不是将它们作为要编译的项目的一部分。

这是我使用 Boost 的项目部分的 CMakeLists.txt

#BOOST

set(BOOST_ROOT /home/neb/workspace/SDLActivityCMAKE/jni/boost)

set(Boost_INCLUDE_DIR /home/neb/workspace/SDLActivityCMAKE/jni/boost/include/boost-1_53)
set(BOOST_INCLUDEDIR /home/neb/workspace/SDLActivityCMAKE/jni/boost/include/boost-1_53)
set(Boost_LIBRARY_DIR /home/neb/workspace/SDLActivityCMAKE/jni/boost/lib)
set(BOOST_LIBRARYDIR /home/neb/workspace/SDLActivityCMAKE/jni/boost/lib)

set(Boost_USE_STATIC_LIBS ON)
set(USE_STATIC_BOOST ON)
set(Boost_USE_STATIC_RUNTIME ON)
set(BOOST_COMPILER gcc)

find_package(Boost COMPONENTS "thread-gcc-mt-1_53" "date_time-gcc-mt-1_53" REQUIRED)

include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIR})
#BOOSTEND

add_executable(main main.cpp)
target_link_libraries( main ${Boost_LIBRARIES} )

当我运行常规 cmake 命令时(cmake .. 来自 android 项目中 jni 文件夹的子目录)没有问题,cmake 找到了库。当我让 cmake 使用上面提到的项目提供的 android.toolchain.cmake 时,我得到了这个(我正在使用 -DBoost_DEBUG 选项)。

-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:566 ] _boost_TEST_VERSIONS = 1.56.0;1.56;1.55.0;1.55;1.54.0;1.54;1.53.0;1.53;1.52.0;1.52;1.51.0;1.51;1.50.0;1.50;1.49.0;1.49;1.48.0;1.48;1.47.0;1.47;1.46.1;1.46.0;1.46;1.45.0;1.45;1.44.0;1.44;1.43.0;1.43;1.42.0;1.42;1.41.0;1.41;1.40.0;1.40;1.39.0;1.39;1.38.0;1.38;1.37.0;1.37;1.36.1;1.36.0;1.36;1.35.1;1.35.0;1.35;1.34.1;1.34.0;1.34;1.33.1;1.33.0;1.33
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:568 ] Boost_USE_MULTITHREADED = TRUE
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:570 ] Boost_USE_STATIC_LIBS = ON
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:572 ] Boost_USE_STATIC_RUNTIME = ON
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:574 ] Boost_ADDITIONAL_VERSIONS =
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:576 ] Boost_NO_SYSTEM_PATHS =
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:644 ] Declared as CMake or Environmental Variables:
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:646 ] BOOST_ROOT = /home/neb/workspace/SDLActivityCMAKE/jni/boost
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:648 ] BOOST_INCLUDEDIR = /home/neb/workspace/SDLActivityCMAKE/jni/boost/include/boost-1_53
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:650 ] BOOST_LIBRARYDIR = /home/neb/workspace/SDLActivityCMAKE/jni/boost/lib
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:652 ] _boost_TEST_VERSIONS = 1.56.0;1.56;1.55.0;1.55;1.54.0;1.54;1.53.0;1.53;1.52.0;1.52;1.51.0;1.51;1.50.0;1.50;1.49.0;1.49;1.48.0;1.48;1.47.0;1.47;1.46.1;1.46.0;1.46;1.45.0;1.45;1.44.0;1.44;1.43.0;1.43;1.42.0;1.42;1.41.0;1.41;1.40.0;1.40;1.39.0;1.39;1.38.0;1.38;1.37.0;1.37;1.36.1;1.36.0;1.36;1.35.1;1.35.0;1.35;1.34.1;1.34.0;1.34;1.33.1;1.33.0;1.33
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:734 ] location of version.hpp: /home/neb/workspace/SDLActivityCMAKE/jni/boost/include/boost-1_53/boost/version.hpp
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:754 ] version.hpp reveals boost 1.53.0
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:786 ] guessed _boost_COMPILER = -gcc46
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:796 ] _boost_MULTITHREADED = -mt
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:839 ] _boost_RELEASE_ABI_TAG = -s
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:841 ] _boost_DEBUG_ABI_TAG = -sd
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:884 ] _boost_LIBRARY_SEARCH_DIRS = /home/neb/workspace/SDLActivityCMAKE/jni/boost/lib;/home/neb/workspace/SDLActivityCMAKE/jni/boost/lib;/home/neb/workspace/SDLActivityCMAKE/jni/boost/stage/lib;/home/neb/workspace/SDLActivityCMAKE/jni/boost/include/boost-1_53/lib;/home/neb/workspace/SDLActivityCMAKE/jni/boost/include/boost-1_53/../lib;/home/neb/workspace/SDLActivityCMAKE/jni/boost/include/boost-1_53/stage/lib;C:/boost/lib;C:/boost;/boost/boost_1_53_0/lib;/boost/boost_1_53/lib;/boost/lib;/boost;/sw/local/lib
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:962 ] Searching for THREAD-GCC-MT-1_53_LIBRARY_RELEASE: boost_thread-gcc-mt-1_53-gcc46-mt-s-1_53;boost_thread-gcc-mt-1_53-gcc46-mt-s;boost_thread-gcc-mt-1_53-mt-s-1_53;boost_thread-gcc-mt-1_53-mt-s;boost_thread-gcc-mt-1_53
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:994 ] Searching for THREAD-GCC-MT-1_53_LIBRARY_DEBUG: boost_thread-gcc-mt-1_53-gcc46-mt-sd-1_53;boost_thread-gcc-mt-1_53-gcc46-mt-sd;boost_thread-gcc-mt-1_53-mt-sd-1_53;boost_thread-gcc-mt-1_53-mt-sd;boost_thread-gcc-mt-1_53-mt;boost_thread-gcc-mt-1_53
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:962 ] Searching for DATE_TIME-GCC-MT-1_53_LIBRARY_RELEASE: boost_date_time-gcc-mt-1_53-gcc46-mt-s-1_53;boost_date_time-gcc-mt-1_53-gcc46-mt-s;boost_date_time-gcc-mt-1_53-mt-s-1_53;boost_date_time-gcc-mt-1_53-mt-s;boost_date_time-gcc-mt-1_53
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:994 ] Searching for DATE_TIME-GCC-MT-1_53_LIBRARY_DEBUG: boost_date_time-gcc-mt-1_53-gcc46-mt-sd-1_53;boost_date_time-gcc-mt-1_53-gcc46-mt-sd;boost_date_time-gcc-mt-1_53-mt-sd-1_53;boost_date_time-gcc-mt-1_53-mt-sd;boost_date_time-gcc-mt-1_53-mt;boost_date_time-gcc-mt-1_53
-- [ /usr/share/cmake-2.8/Modules/FindBoost.cmake:1108 ] Boost_FOUND = FALSE
CMake Error at /usr/share/cmake-2.8/Modules/FindBoost.cmake:1195 (message):
Unable to find the requested Boost libraries.

Boost version: 1.53.0

Boost include path:
/home/neb/workspace/SDLActivityCMAKE/jni/boost/include/boost-1_53

The following Boost libraries could not be found:

boost_thread-gcc-mt-1_53
boost_date_time-gcc-mt-1_53

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):
src/CMakeLists.txt:15 (find_package)


-- Configuring incomplete, errors occurred!

所以我看到 CMake 正在这个确切目录中搜索库:/home/neb/workspace/SDLActivityCMAKE/jni/boost/lib其中有编译好的静态库:

neb@neb-VirtualBox:~/workspace/SDLActivityCMAKE/jni/boost/lib$ ls -l
total 24440
-rwxrwxrwx 1 neb neb 557190 sie 27 12:36 libboost_date_time-gcc-mt-1_53.a
-rwxrwxrwx 1 neb neb 1348474 sie 27 12:36 libboost_filesystem-gcc-mt-1_53.a
-rwxrwxrwx 1 neb neb 827216 sie 27 12:36 libboost_iostreams-gcc-mt-1_53.a
-rwxrwxrwx 1 neb neb 6813972 sie 27 12:36 libboost_program_options-gcc-mt-1_53.a
-rwxrwxrwx 1 neb neb 12927086 sie 27 12:37 libboost_regex-gcc-mt-1_53.a
-rwxrwxrwx 1 neb neb 1197696 sie 27 12:37 libboost_signals-gcc-mt-1_53.a
-rwxrwxrwx 1 neb neb 159462 sie 27 12:36 libboost_system-gcc-mt-1_53.a
-rwxrwxrwx 1 neb neb 1177994 sie 27 12:37 libboost_thread-gcc-mt-1_53.a`

我设置了所有指向我能找到的 BOOST 目录的变量,我设置了变量说 Boost 库应该是静态的,但它仍然找不到它们。我还能做什么?

最佳答案

使用 CMake 寻找 Boost

首先让我说让 CMake 找到 Boost 可能很困难,因为 FindBoost.cmake 中的自动魔法会咬你,而 CMake 的制造商 KitWare 拥有任何流行项目中最糟糕的文档我曾经遇到过。如果失败,您必须遍历 FindBoost.cmake 的源代码来调试它。

交叉编译的Boost

假设 1.62.0,你安装交叉编译的 boost 的目录是这样的

boost-arm-build/include
boost-arm-build/include/boost-1_62
boost-arm-build/lib

从 Project-Build 目录调用 CMake

cmake \
-DBoost_NO_SYSTEM_PATHS=TRUE \
-DBoost_ADDITIONAL_VERSIONS="1.62" \
-DCMAKE_TOOLCHAIN_FILE=../android.toolchain \
-DBOOST_ROOT="../boost-arm-build" \
../Project/

-DBoost_ADDITIONAL_VERSIONS - CMake 使用硬编码的字符串列表查找 Boost,如果您的 CMake 比您正在构建的 Boost 版本旧,它将不知道在 include 目录中查找的位置,因此你需要传递它。虽然版本实际上是 1.62.0,但 boost 将 includes 放在 boost-1_62 中,所以我改用 1.62。在 FindBoost.cmake 中,您会发现每个版本都添加了两次,例如“1.62.0”和“1.62”正是出于这个原因。

您还应该检查您构建的库的文件名,对于我的示例,让我们看看系统:

libboost_system-gcc-mt-1_62.a
libboost_system-gcc-mt-1_62.so # Symbolic link to libboost_system-gcc-mt-1_62.so.1.62.0
libboost_system-gcc-mt-1_62.so.1.62.0
libboost_system-gcc-mt-d-1_62.a
libboost_system-gcc-mt-d-1_62.so # Symbolic link to libboost_system-gcc-mt-d-1_62.so.1.62.0
libboost_system-gcc-mt-d-1_62.so.1.62.0
  • gcc - 使用的编译器
  • mt - 多线程
  • d - 调试
  • 1_62 - 显然是 boost 的版本

如果您看到的是 libboost_system.a,则表示您未能使用 --with-layout=versioned 构建 boost,应该查看我的 SO Answer on building boost using the NDK .如果您看到 clang 而不是 gcc,那么您已经使用 clang 构建了 boost,但您可能需要使用 Boost_COMPILER 标志通知 CMake clang 存在。

-DBoost_COMPILER="-clang"

android.toolchain 文件

set(CMAKE_SYSTEM_NAME Android)

set(CROSS_COMPILER_DIR /opt/ndk-R13-standalone)
set(CMAKE_C_COMPILER ${CROSS_COMPILER_DIR}/bin/arm-linux-androideabi-gcc)
set(CMAKE_CXX_COMPILER ${CROSS_COMPILER_DIR}/bin/arm-linux-androideabi-g++)

set(ANDROID_NATIVE_API_LEVEL android-19)
set(ANDROID_ABI armeabi-v7a)
set(ANDROID_STL gnustl_static)

set(CMAKE_SYSROOT ${CROSS_COMPILER_DIR}/sysroot)
set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT})

# search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

关于c++ - CMake 在使用 android-cmake 工具链文件时找不到 Boost 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18715694/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com