【问题标题】:C++ cmake & boost & arm cross compilationC++ cmake & boost & arm 交叉编译
【发布时间】:2016-01-15 19:16:31
【问题描述】:

我在使用 boost 和 cmake 编译程序时遇到问题。我使用 gcc-linaro-arm-linux-gnueabihf-4.9/bin/arm-linux-gnueabihf-g++ 编译器进行交叉编译。 现在我有 cmake 文件,例如:

cmake_minimum_required (VERSION 2.6.2)
project (xxx)

SET(CMAKE_CXX_COMPILER /home/kamil/gcc-linaro-arm-linux-gnueabihf-4.9/bin/arm-linux-gnueabihf-g++)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread -Dtypeof=__typeof__ -D_GLIBCXX_USE_CXX11_ABI=0 -Wall -Werror -Wextra -Wno-error=array-bounds")

if(DEFINED ENV{SDKTARGETSYSROOT})
    set(CMAKE_FIND_ROOT_PATH $ENV{SDKTARGETSYSROOT})
    set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
    set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
    set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
endif(DEFINED ENV{SDKTARGETSYSROOT})

find_package(Boost COMPONENTS system filesystem REQUIRED)

include_directories("/usr/local/include")
include_directories(${Boost_INCLUDE_DIRS})

enable_testing()
set(CMAKE_CTEST_COMMAND ctest -V)
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} )

add_subdirectory(src)
add_subdirectory(test EXCLUDE_FROM_ALL)

add_executable(xxxx
    main.cpp
    ...cpp
    ...cpp
    ...cpp
    ...cpp
)

target_link_libraries(xxxx
    ${Boost_SYSTEM_LIBRARY}
    ${Boost_THREAD_LIBRARY}
)

install(TARGETS xxxx
    DESTINATION bin
    PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE
    WORLD_READ WORLD_EXECUTE
)

现在在 linux(Ubuntu) 中使用命令时:

  • cmake ..
  • 制作

我有回复:

kamil@kamil:~/test/build$ rm -rf *
kamil@kamil:~/test/build$ cmake ..
-- The C compiler identification is GNU 4.8.4
-- The CXX compiler identification is GNU 4.8.4
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Boost version: 1.55.0
-- Found the following Boost libraries:
--   system
--   filesystem
-- Found GTest: /usr/local/lib/libgtest.so  
-- Configuring done
-- Generating done
-- Build files have been written to: /home/kamil/test/build
kamil@kamil:~/test/build$ make
Scanning dependencies of target xxxx
[ 12%] Building CXX object src/CMakeFiles/test.dir/main.cpp.o
In file included from /home/test/src/test/utils/logger.hpp:4:0,
                 from /home/kamil/test/src/main.cpp:9:
/home/kamil/test/src/test/utils/singleton.hpp:5:33: fatal error: boost/noncopyable.hpp: No such file or directory
 #include <boost/noncopyable.hpp>
                                 ^
compilation terminated.
make[2]: *** [src/CMakeFiles/test.dir/main.cpp.o] Error 1
make[1]: *** [src/CMakeFiles/test.dir/all] Error 2
make: *** [all] Error 2

错误:

fatal error: boost/noncopyable.hpp: No such file or directory
     #include <boost/noncopyable.hpp>

当我在 cmake 中评论以下行时:

SET(CMAKE_CXX_COMPILER /home/kamil/toradex/gcc-linaro-arm-linux-gnueabihf-4.9/bin/arm-linux-gnueabihf-g++)

然后一切正常。

我在 Ubuntu 中使用命令安装 boost:sudo apt-get install libboost1.55-all-dev

使用 linux-gnueabihf-g++ 编译有什么问题以及如何解决。

【问题讨论】:

  • 交叉编译时,您需要为目标机器构建所有库,而不是为主机(您构建项目的主机)。此外,在 CMake 中,交叉编译通常意味着使用 toolchain file,它不仅设置编译器,还设置目标架构、库路径等。
  • 虽然 Tsyarev 是正确的,一般来说,您需要为目标平台编译依赖项,但对于 Boost,您可能不必这样做。 Boost 的许多功能是“仅标题”,因此,您可能不必使用 linaro 工具链实际构建 boost。如果你通过调用“make VERBOSE=1”来运行make,输出是什么?您应该看到通过 -I 标志传递给编译器的 boost 头文件路径。看起来它没有正确通过。
  • 你说得对。使用“make VERBOSE=1”,我看不到带有 boost 文件路径的 -I 标志。那么我应该使用 linaro 工具链构建 boost 吗?像这样的东西:cnx-software.com/2011/10/03/…?然后一切都应该没问题吗?还有什么我应该做的吗?
  • 尝试添加target_include_directories(xxxx PRIVATE ${Boost_INCLUDE_DIRS})。这应该将正确的包含添加到您的目标中。
  • 同样的结果。 “致命错误:boost/noncopyable.hpp:没有这样的文件或目录”。

标签: c++ boost cmake arm cross-compiling


【解决方案1】:

使用 gcc-linaro-arm-linux-gnueabihf-4.9 编译 boost 有效。 求助链接:http://www.cnx-software.com/2011/10/03/cross-compiling-boost-c-libraries-for-arm/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-02
    • 1970-01-01
    • 1970-01-01
    • 2019-11-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多