C++ cmake & boost & arm cross compilation

2019-05-15 00:49发布

I have a problem with compiling my program with boost and cmake. I use cross-compilation with using gcc-linaro-arm-linux-gnueabihf-4.9/bin/arm-linux-gnueabihf-g++ compiler. And now I have cmake file like:

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)

and

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
)

And now when use commands in linux(Ubuntu):

  • cmake ..
  • make

I have response at:

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

Error:

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

When I comment on the following line in cmake:

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

then everything is ok.

I install boost in Ubuntu with command: sudo apt-get install libboost1.55-all-dev

What is wrong with compiling with linux-gnueabihf-g++ and how to fix it.

1条回答
你好瞎i
2楼-- · 2019-05-15 01:16

Compiling boost with gcc-linaro-arm-linux-gnueabihf-4.9 worked. Helps link: http://www.cnx-software.com/2011/10/03/cross-compiling-boost-c-libraries-for-arm/

查看更多
登录 后发表回答