CMake交叉编译错误(缺少-lm -lc和crt0.o)

时间:2018-10-23 06:52:44

标签: c++ linux cmake cross-compiling embedded-linux

我用C ++(main.cppprint.cppprint.h)编写了一个简单的helloworld程序,我想使用CMake将其交叉编译到ARM。但我收到有关丢失文件的错误。以下是make的输出:

/usr/bin/cmake -H/home/eslam/eslamlearning/learning/CPPtest -B/home/eslam/eslamlearning/learning/CPPtest --check-build-system CMakeFiles/Makefile.cmake 0
/usr/bin/cmake -E cmake_progress_start /home/eslam/eslamlearning/learning/CPPtest/CMakeFiles /home/eslam/eslamlearning/learning/CPPtest/CMakeFiles/progress.marks
make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/eslam/eslamlearning/learning/CPPtest'
make -f CMakeFiles/LibsModule.dir/build.make CMakeFiles/LibsModule.dir/depend
make[2]: Entering directory '/home/eslam/eslamlearning/learning/CPPtest'
cd /home/eslam/eslamlearning/learning/CPPtest && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/eslam/eslamlearning/learning/CPPtest /home/eslam/eslamlearning/learning/CPPtest /home/eslam/eslamlearning/learning/CPPtest /home/eslam/eslamlearning/learning/CPPtest /home/eslam/eslamlearning/learning/CPPtest/CMakeFiles/LibsModule.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/eslam/eslamlearning/learning/CPPtest'
make -f CMakeFiles/LibsModule.dir/build.make CMakeFiles/LibsModule.dir/build
make[2]: Entering directory '/home/eslam/eslamlearning/learning/CPPtest'
[ 25%] Linking CXX static library libLibsModule.a
/usr/bin/cmake -P CMakeFiles/LibsModule.dir/cmake_clean_target.cmake
/usr/bin/cmake -E cmake_link_script CMakeFiles/LibsModule.dir/link.txt --verbose=1
/home/eslam/eslamlearning/gcc-arm-eabi-toolchains/bin/arm-eabi-ar qc libLibsModule.a  CMakeFiles/LibsModule.dir/print.cpp.o
/usr/bin/ranlib libLibsModule.a
make[2]: Leaving directory '/home/eslam/eslamlearning/learning/CPPtest'
[ 50%] Built target LibsModule
make -f CMakeFiles/StaticTest.dir/build.make CMakeFiles/StaticTest.dir/depend
make[2]: Entering directory '/home/eslam/eslamlearning/learning/CPPtest'
cd /home/eslam/eslamlearning/learning/CPPtest && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/eslam/eslamlearning/learning/CPPtest /home/eslam/eslamlearning/learning/CPPtest /home/eslam/eslamlearning/learning/CPPtest /home/eslam/eslamlearning/learning/CPPtest /home/eslam/eslamlearning/learning/CPPtest/CMakeFiles/StaticTest.dir/DependInfo.cmake --color=
make[2]: Leaving directory '/home/eslam/eslamlearning/learning/CPPtest'
make -f CMakeFiles/StaticTest.dir/build.make CMakeFiles/StaticTest.dir/build
make[2]: Entering directory '/home/eslam/eslamlearning/learning/CPPtest'
[ 75%] Linking CXX executable StaticTest
/usr/bin/cmake -E cmake_link_script CMakeFiles/StaticTest.dir/link.txt --verbose=1
/home/eslam/eslamlearning/gcc-arm-eabi-toolchains/bin/arm-eabi-g++ --sysroot=/home/eslam/     CMakeFiles/StaticTest.dir/main.cpp.o  -o StaticTest libLibsModule.a 
/home/eslam/eslamlearning/gcc-arm-eabi-toolchains/bin/../lib/gcc/arm-eabi/7.3.1/../../../../arm-eabi/bin/ld: cannot find crt0.o: No such file or directory
/home/eslam/eslamlearning/gcc-arm-eabi-toolchains/bin/../lib/gcc/arm-eabi/7.3.1/../../../../arm-eabi/bin/ld: cannot find -lm
/home/eslam/eslamlearning/gcc-arm-eabi-toolchains/bin/../lib/gcc/arm-eabi/7.3.1/../../../../arm-eabi/bin/ld: cannot find -lc
collect2: error: ld returned 1 exit status
CMakeFiles/StaticTest.dir/build.make:98: recipe for target 'StaticTest' failed
make[2]: *** [StaticTest] Error 1
make[2]: Leaving directory '/home/eslam/eslamlearning/learning/CPPtest'
CMakeFiles/Makefile2:107: recipe for target 'CMakeFiles/StaticTest.dir/all' failed
make[1]: *** [CMakeFiles/StaticTest.dir/all] Error 2
make[1]: Leaving directory '/home/eslam/eslamlearning/learning/CPPtest'
Makefile:86: recipe for target 'all' failed
make: *** [all] Error 2

这是我的CMakelists.txt

cmake_minimum_required(VERSION 3.10.2)
project (StaticTest)
enable_language(CXX)
SET(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_PROCESSOR arm)
SET(CMAKE_C_COMPILER   /home/eslam/eslamlearning/gcc-arm-eabi-toolchains/bin/arm-eabi-gcc)
SET(CMAKE_CXX_COMPILER /home/eslam/eslamlearning/gcc-arm-eabi-toolchains/bin/arm-eabi-g++)
set(CMAKE_AR /home/eslam/eslamlearning/gcc-arm-eabi-toolchains/bin/arm-eabi-ar)
set(CMAKE_FIND_ROOT_PATH /home/eslam/eslamlearning/gcc-arm-eabi-toolchains)
set(CMAKE_SYSROOT /home/eslam/)

set(CMAKE_STAGING_PREFIX /home/eslam/eslamlearning/learning/CPPtest)

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH)

ADD_LIBRARY(LibsModule STATIC 
    print.cpp
)
SET( APP_EXE StaticTest )
add_executable(${APP_EXE} main.cpp)

TARGET_LINK_LIBRARIES(LibsModule )
TARGET_LINK_LIBRARIES( ${APP_EXE}
                       LibsModule )

我想念什么?顺便说一句,我不确定我的SYSROOT路径是否正确。

最后一个问题:我正在阅读https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/CrossCompiling#the-toolchain-file,什么是目标环境

0 个答案:

没有答案