简体   繁体   English

cmake交叉编译boost链接错误

[英]cmake cross compile boost link error

For my program I want to use some boost libraries but when I make the program I get the error: 对于我的程序,我想使用一些Boost库,但是在制作程序时出现错误:

/home/ubunturik/rpinew/rootfs/usr/lib/arm-linux-gnueabihf/libboost_regex.so: undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)@GLIBCXX_3.4.20'
/home/ubunturik/rpinew/rootfs/usr/lib/arm-linux-gnueabihf/libicuuc.so.52: undefined reference to `__cxa_throw_bad_array_new_length@CXXABI_1.3.8'
collect2: error: ld returned 1 exit st

I followed this tutorial http://amgaera.github.io/blog/2014/04/10/cross-compiling-for-raspberry-pi-on-64-bit-linux/ . 我遵循了本教程http://amgaera.github.io/blog/2014/04/10/cross-compiling-for-raspberry-pi-on-64-bit-linux/ To get boost I used apt install libboost-all-dev on the raspberry pi and used those files. 为了获得增强,我使用apt在树莓派上安装libboost-all-dev并使用了这些文件。

Cmake file: CMake文件:

cmake_minimum_required(VERSION 3.5)
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_SYSTEM_VERSION 1)

# Specify the cross compiler
SET(CMAKE_C_COMPILER $ENV{HOME}/rpinew/toolchain/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-gcc)
SET(CMAKE_CXX_COMPILER $ENV{HOME}/rpinew/toolchain/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/arm-linux-gnueabihf-g++)

# Where is the target environment
SET(CMAKE_FIND_ROOT_PATH $ENV{HOME}/rpinew/rootfs)
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} --sysroot=${CMAKE_FIND_ROOT_PATH}")
SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} --sysroot=${CMAKE_FIND_ROOT_PATH}")
SET(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} --sysroot=${CMAKE_FIND_ROOT_PATH}")

# Search for programs only in the build host directories
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

# Search for libraries and headers only in the target directories
SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

#for boost
set(Boost_INCLUDE_DIR /home/ubunturik/rpinew/rootfs/usr/include)
set(Boost_LIBRARY_DIR /home/ubunturik/rpinew/rootfs/usr/lib/arm-linux-gnueabihf)
find_package(Boost COMPONENTS regex date_time system chrono filesystem program_options thread REQUIRED)
include_directories(${Boost_INCLUDE_DIR})
link_directories(${Boost_LIBRARY_DIR})

#Bring the headers, such as Student.h into the project
include_directories(include)

include_directories($ENV{HOME}/rpinew/rootfs/usr/include/arm-linux-gnueabihf)

#However, the file(GLOB...) allows for wildcard additions:
file(GLOB SOURCES "src/*.cpp")

add_executable(MonitorApp ${SOURCES})
target_link_libraries(MonitorApp ${PROJECT_LINK_LIBS} ${Boost_LIBRARIES})

How do I solve this? 我该如何解决?

You are heading for cross-compilation, so you installed specific toolchain (compiler, libs etc). 您将要进行交叉编译,因此您安装了特定的工具链(编译器,库等)。 Then you tried using usual boost libraries, which were built using ordinary compiler and which depends on ordinary libs. 然后,您尝试使用普通的boost库,该库使用普通的编译器构建,并且依赖于普通的库。 Fail isn't that surprising, is it? 失败并不令人惊讶,是吗?

I don't know if there is a simple way, but compiling boost from source code using your compiler and libraries intended for Raspberry Pi should do the trick. 我不知道是否有一种简单的方法,但是使用用于Raspberry Pi的编译器和库从源代码编译boost应该可以解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM