使用外部 SDK 工具链文件在 VisualStudio 上进行 CMake 项目编译错误

问题描述 投票:0回答:1

我正在 Windows 机器上使用 VisualStudio CMake 项目

我正在使用外部 SDK交叉编译我的 C++ 程序用于 Linux Arm 架构

我将 SDK 工具链添加到 cmakeToolchain 路径:

/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake

这是我的 CMakeLists.txt 文件:

set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)

set(Boost_USE_STATIC_LIBS ON) 
set(Boost_USE_MULTITHREADED OFF)  
set(Boost_USE_STATIC_RUNTIME OFF)
#list(APPEND CMAKE_PREFIX_PATH /home/ubuntu/linux4sam/poky/build-microchip/tmp/sysroots-components/cortexa5hf-neon/boost/usr/include/boost)
list(APPEND CMAKE_PREFIX_PATH /opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/include)
Set(Boost_NO_BOOST_CMAKE ON)
#set(BOOST_ROOT "/home/ubuntu/linux4sam/poky/build-microchip/tmp/sysroots-components/cortexa5hf-neon/boost")

message(STATUS "CMAKE_TOOLCHAIN_FILE='${CMAKE_TOOLCHAIN_FILE}'")
set(CROSS_COMPILER_DIR /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr)
set(CMAKE_C_COMPILER ${CROSS_COMPILER_DIR}/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc)
set(CMAKE_CXX_COMPILER ${CROSS_COMPILER_DIR}/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc)

#set(CMAKE_SYSTEM_NAME Linux)

message(STATUS "CMAKE_C_COMPILER='${CMAKE_C_COMPILER}'")
message(STATUS "CMAKE_CXX_COMPILER='${CMAKE_CXX_COMPILER}'")

find_package(Boost 1.66.0) 

if(Boost_FOUND)

    message (STATUS "success!")
    add_executable (CMakeProject4 "CMakeProject4.cpp" "CMakeProject4.h") 
    include_directories(${Boost_INCLUDE_DIRS})  
    target_link_libraries(CMakeProject4 ${Boost_LIBRARIES})

endif()

如您所见,我将 SDK 编译器 bin 路径设置为 CMAKE_C_COMPILERCMAKE_CXX_COMPILER 变量。

当我调试时,我发现:

1> Copying files to the remote machine.
1> Starting copying files to remote machine.
1> [rsync] rsync -t --delete --delete-excluded -v -r --exclude=.vs --exclude=.git --exclude=out  "." rsync://ubuntu@localhost:56934/-home-ubuntu-CMake-RemoteCML
1> [rsync] sending incremental file list
1> [rsync] 
1> [rsync] sent 229 bytes  received 13 bytes  161.33 bytes/sec
1> [rsync] total size is 4,429  speedup is 18.30
1> Finished copying files (elapsed time 00h:00m:04s:043ms).
1> CMake generation started for configuration: 'Linux-Release'.
1> Found cmake executable at /home/ubuntu/.vs/cmake/bin/cmake.
1> /home/ubuntu/.vs/cmake/bin/cmake -G "Unix Makefiles"  -DCMAKE_BUILD_TYPE="RelWithDebInfo" -DBoost_INCLUDE_DIRS:PATH="/opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/include" -DBoost_LIBRARIES:PATH="/opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/lib" -DBoost_INCLUDE_DIR:PATH="/opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/include" -DBoost_DEBUG=ON -DCMAKE_CXX_COMPILER=/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc -DCMAKE_TOOLCHAIN_FILE="/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake" -DCMAKE_INSTALL_PREFIX=/home/ubuntu/CMake/RemoteIL "/home/ubuntu/CMake/RemoteCML/CMakeLists.txt";
1> [CMake] -- The C compiler identification is GNU 7.4.0
1> [CMake] -- The CXX compiler identification is GNU 7.3.0
1> [CMake] -- Check for working C compiler: /usr/bin/cc
1> [CMake] -- Check for working C compiler: /usr/bin/cc -- works
1> [CMake] -- Detecting C compiler ABI info
1> [CMake] -- Detecting C compiler ABI info - done
1> [CMake] -- Detecting C compile features
1> [CMake] -- Detecting C compile features - done
1> [CMake] -- Check for working CXX compiler: /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc
1> [CMake] -- Check for working CXX compiler: /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc -- broken
1> [CMake] CMake Error at /home/ubuntu/.vs/cmake/share/cmake-3.15/Modules/CMakeTestCXXCompiler.cmake:53 (message):
1> [CMake]   The C++ compiler
1> [CMake] 
1> [CMake]     "/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc"
1> [CMake] 
1> [CMake]   is not able to compile a simple test program.
1> [CMake] 
1> [CMake]   It fails with the following output:
1> [CMake] 
1> [CMake]     Change Dir: /home/ubuntu/CMake/RemoteBR/CMakeFiles/CMakeTmp
1> [CMake]     
1> [CMake]     Run Build Command(s):/usr/bin/make cmTC_2cb5a/fast && /usr/bin/make -f CMakeFiles/cmTC_2cb5a.dir/build.make CMakeFiles/cmTC_2cb5a.dir/build
1> [CMake]     make[1]: Entering directory '/home/ubuntu/CMake/RemoteBR/CMakeFiles/CMakeTmp'
1> [CMake]     Building CXX object CMakeFiles/cmTC_2cb5a.dir/testCXXCompiler.cxx.o
1> [CMake]     /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc     -o CMakeFiles/cmTC_2cb5a.dir/testCXXCompiler.cxx.o -c /home/ubuntu/CMake/RemoteBR/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
1> [CMake]     Linking CXX executable cmTC_2cb5a
1> [CMake]     /home/ubuntu/.vs/cmake/bin/cmake -E cmake_link_script CMakeFiles/cmTC_2cb5a.dir/link.txt --verbose=1
1> [CMake]     /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc       CMakeFiles/cmTC_2cb5a.dir/testCXXCompiler.cxx.o  -o cmTC_2cb5a 
1> [CMake]     /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/7.3.0/real-ld: cannot find crt1.o: No such file or directory
1> [CMake]     /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/7.3.0/real-ld: cannot find crti.o: No such file or directory
1> [CMake]     /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/7.3.0/real-ld: cannot find crtbegin.o: No such file or directory
1> [CMake]     /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/7.3.0/real-ld: cannot find -lgcc
1> [CMake]     /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/7.3.0/real-ld: cannot find -lgcc_s
1> [CMake]     /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/7.3.0/real-ld: cannot find -lc
1> [CMake]     /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/7.3.0/real-ld: cannot find -lgcc
1> [CMake]     /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/7.3.0/real-ld: cannot find -lgcc_s
1> [CMake]     /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/7.3.0/real-ld: cannot find crtend.o: No such file or directory
1> [CMake]     /opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/7.3.0/real-ld: cannot find crtn.o: No such file or directory
1> [CMake]     collect2: error: ld returned 1 exit status
1> [CMake]     CMakeFiles/cmTC_2cb5a.dir/build.make:86: recipe for target 'cmTC_2cb5a' failed
1> [CMake]     make[1]: *** [cmTC_2cb5a] Error 1
1> [CMake]     make[1]: Leaving directory '/home/ubuntu/CMake/RemoteBR/CMakeFiles/CMakeTmp'
1> [CMake]     Makefile:121: recipe for target 'cmTC_2cb5a/fast' failed
1> [CMake]     make: *** [cmTC_2cb5a/fast] Error 2
1> [CMake]     
1> [CMake] 
1> [CMake]   CMake will not be able to correctly generate this project.
1> [CMake] Call Stack (most recent call first):
1> [CMake]   CMakeLists.txt:6 (project)
1> [CMake] -- Configuring incomplete, errors occurred!
1> [CMake] See also "/home/ubuntu/CMake/RemoteBR/CMakeFiles/CMakeOutput.log".
1> [CMake] See also "/home/ubuntu/CMake/RemoteBR/CMakeFiles/CMakeError.log".
1> cd "/home/ubuntu/CMake/RemoteBR";/home/ubuntu/.vs/cmake/bin/cmake -G "Unix Makefiles"  -DCMAKE_BUILD_TYPE="RelWithDebInfo" -DBoost_INCLUDE_DIRS:PATH="/opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/include" -DBoost_LIBRARIES:PATH="/opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/lib" -DBoost_INCLUDE_DIR:PATH="/opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr/include" -DBoost_DEBUG=ON -DCMAKE_CXX_COMPILER=/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc -DCMAKE_TOOLCHAIN_FILE="/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake" -DCMAKE_INSTALL_PREFIX=/home/ubuntu/CMake/RemoteIL "/home/ubuntu/CMake/RemoteCML" 2>&1; returned with exit code: 1

我可以在这里看到,CMake 可以识别我想要使用的 SDK 工具链编译器,即 GNU 7.3.0,但它已损坏! 当我打开 CMakeCache.txt 时,我发现这个:

//No help, variable specified on the command line.
CMAKE_CXX_COMPILER:UNINITIALIZED=/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc

//A wrapper around 'ar' adding the appropriate '--plugin' option
// for the GCC compiler
CMAKE_CXX_COMPILER_AR:FILEPATH=/usr/bin/gcc-ar-7

//A wrapper around 'ranlib' adding the appropriate '--plugin' option
// for the GCC compiler
CMAKE_CXX_COMPILER_RANLIB:FILEPATH=/usr/bin/gcc-ranlib-7

CMAKE_CXX_FLAGS:STRING=

//Flags used by the CXX compiler during DEBUG builds.
CMAKE_CXX_FLAGS_DEBUG:STRING=-g

//Flags used by the CXX compiler during MINSIZEREL builds.
CMAKE_CXX_FLAGS_MINSIZEREL:STRING=-Os -DNDEBUG

//Flags used by the CXX compiler during RELEASE builds.
CMAKE_CXX_FLAGS_RELEASE:STRING=-O3 -DNDEBUG

//Flags used by the CXX compiler during RELWITHDEBINFO builds.
CMAKE_CXX_FLAGS_RELWITHDEBINFO:STRING=-O2 -g -DNDEBUG

//No help, variable specified on the command line.
CMAKE_TOOLCHAIN_FILE:UNINITIALIZED=/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake

这是我的 C++ .cpp 文件程序:

#include "CMakeProject4.h"
#include <boost/lambda/lambda.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

int main()
{
    typedef std::istream_iterator<int> in;

    std::cout << "Type in any number: ";

    std::for_each(
        in(std::cin), in(), std::cout
        << (boost::lambda::_1 * 10)
        << "\nType in another number: ");
}

但是当我尝试运行 CMake 以便使用以下命令编译我的程序时:

cmake -DBoost_DEBUG=ON -DCMAKE_CXX_COMPILER=/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi/arm-poky-linux-gnueabi-gcc

我有这个错误:

编译错误

请问有什么帮助吗?

c++ visual-studio cmake sdk cross-compiling
1个回答
1
投票

当您使用工具链文件时,您不应自行设置编译器。您应该将其留给工具链文件,因为它知道如何交叉编译。像

CMAKE_SYSTEM_NAME
CMAKE_SYSTEM_PROCESSOR
这样的东西应该留在工具链文件中。

set(Boost_USE_STATIC_LIBS ON) 
set(Boost_USE_MULTITHREADED OFF)  
set(Boost_USE_STATIC_RUNTIME OFF)
set(Boost_NO_BOOST_CMAKE ON)

# I think the prefix should point to usr directly, not to the include directory
list(APPEND CMAKE_PREFIX_PATH /opt/poky-atmel/2.5.3/sysroots/cortexa5hf-neon-poky-linux-gnueabi/usr)

message(STATUS "CMAKE_TOOLCHAIN_FILE='${CMAKE_TOOLCHAIN_FILE}'")
message(STATUS "CMAKE_C_COMPILER='${CMAKE_C_COMPILER}'")
message(STATUS "CMAKE_CXX_COMPILER='${CMAKE_CXX_COMPILER}'")

project(whatever CXX)

# Better to fail fast when there's a package missing
find_package(Boost 1.66.0 REQUIRED) 

add_executable (CMakeProject4 CMakeProject4.cpp CMakeProject4.h) 
target_link_libraries(CMakeProject4 PRIVATE Boost::headers)

你的 CMake 参数应该如下所示:

cmake -DCMAKE_TOOLCHAIN_FILE=/opt/poky-atmel/2.5.3/sysroots/x86_64-pokysdk-linux/usr/share/cmake/OEToolchainConfig.cmake
© www.soinside.com 2019 - 2024. All rights reserved.