交叉编译:添加符号时出错:格式错误的文件collect2:错误:ld返回1退出状态

时间:2020-07-02 17:44:40

标签: c++ boost cmake cross-compiling windows-subsystem-for-linux

用于aarch64编译器的交叉编译c ++测试应用程序,并使用Cmake文件链接boost库。我不断收到错误消息,认为Boost库的格式不正确。这是我的CMakeList和错误消息。

CMakeLists.txt:

cmake_minimum_required(VERSION "3.10.2")


project(testapp2)

# Target operating system name.
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
# Name of C compiler.
set(CMAKE_C_COMPILER "aarch64-linux-gnu-gcc")
set(CMAKE_CXX_COMPILER "aarch64-linux-gnu-g++")

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED True)
#set(CMAKE_CXX_FLAGS "-m32")
set(BOOST_ROOT "./local/boost_1_73_0") # either set it here or from the command line  
set(Boost_USE_STATIC_LIBS OFF) 
set(Boost_USE_MULTITHREADED ON)  
set(Boost_USE_STATIC_RUNTIME OFF) 
set(Boost_INCLUDE_DIRS "./local/boost_1_73_0/boost")
find_package(Boost REQUIRED COMPONENTS system)

add_executable(testapp2 main.cpp)

install(TARGETS testapp2 DESTINATION bin)

install(FILES main.cpp DESTINATION src)

target_include_directories(testapp2 PUBLIC ${Boost_INCLUDE_DIRS})
target_link_libraries(testapp2 ${Boost_LIBRARIES})

错误:

usr/lib/x86_64-linux-gnu/libboost_system.so: error adding symbols: File in wrong format
collect2: error: ld returned 1 exit status

我尝试添加-DCMAKE_CXX_FLAGS =“ m32”,它给了我这个错误:

CMake Error at /usr/share/cmake-3.10/Modules/CMakeTestCXXCompiler.cmake:45 (message):
  The C++ compiler

    "/usr/bin/c++"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /root/testapp2/build/CMakeFiles/CMakeTmp

    Run Build Command:"/usr/bin/make" "cmTC_3dc9d/fast"
    /usr/bin/make -f CMakeFiles/cmTC_3dc9d.dir/build.make CMakeFiles/cmTC_3dc9d.dir/build
    make[1]: Entering directory '/root/testapp2/build/CMakeFiles/CMakeTmp'
    Building CXX object CMakeFiles/cmTC_3dc9d.dir/testCXXCompiler.cxx.o
    /usr/bin/c++    m32    -o CMakeFiles/cmTC_3dc9d.dir/testCXXCompiler.cxx.o -c /root/testapp2/build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
    c++: error: m32: No such file or directory

0 个答案:

没有答案
相关问题