主题:cmake交叉编译错误

  共有29318人关注过本帖    
客人
1楼


cmake交叉编译错误  发帖心情 Post By:2019-4-2 17:34:00   [只看该作者]

使用 ESM6802-toolchain-x86_64-qt5-8.sh 安装编译工具链。使用默认安装目录/opt/fsl-imx-x11/4.1.15-2.0.1/sysroots/


编译目录如下面

cmake-test

|-- build
|-- CMakeLists.txt
|-- cross-compile.txt
`-- hello.cpp

使用其他家的交叉编译器没有问题。使用你们家的出现如下编译错误

newrt@newrt-desktop:~/Documents/cmake-test/build$ cmake -DCMAKE_TOOLCHAIN_FILE=../cross-compile.txt ..
-- The C compiler identification is GNU 5.3.0
-- The CXX compiler identification is GNU 5.3.0
-- Check for working C compiler: /opt/fsl-imx-x11/4.1.15-2.0.1/sysroots/x86_64-pokysdk-linux/usr/bin/arm-emtronix-linux-gnueabi/arm-emtronix-linux-gnueabi-gcc
-- Check for working C compiler: /opt/fsl-imx-x11/4.1.15-2.0.1/sysroots/x86_64-pokysdk-linux/usr/bin/arm-emtronix-linux-gnueabi/arm-emtronix-linux-gnueabi-gcc -- broken
CMake Error at /usr/share/cmake-3.12/Modules/CMakeTestCCompiler.cmake:52 (message):
  The C compiler

    "/opt/fsl-imx-x11/4.1.15-2.0.1/sysroots/x86_64-pokysdk-linux/usr/bin/arm-emtronix-linux-gnueabi/arm-emtronix-linux-gnueabi-gcc"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /home/newrt/Documents/cmake-test/build/CMakeFiles/CMakeTmp
   
    Run Build Command:"/usr/bin/make" "cmTC_167cc/fast"
    /usr/bin/make -f CMakeFiles/cmTC_167cc.dir/build.make CMakeFiles/cmTC_167cc.dir/build
    make[1]: ����Ŀ¼��/home/newrt/Documents/cmake-test/build/CMakeFiles/CMakeTmp��
    Building C object CMakeFiles/cmTC_167cc.dir/testCCompiler.c.o
    /opt/fsl-imx-x11/4.1.15-2.0.1/sysroots/x86_64-pokysdk-linux/usr/bin/arm-emtronix-linux-gnueabi/arm-emtronix-linux-gnueabi-gcc  -I/opt/fsl-imx-x11/4.1.15-2.0.1/sysroots/cortexa9hf-neon-emtronix-linux-gnueabi/include/c++/5.3.0 -I/opt/fsl-imx-x11/4.1.15-2.0.1/sysroots/cortexa9hf-neon-emtronix-linux-gnueabi/usr/include   -o CMakeFiles/cmTC_167cc.dir/testCCompiler.c.o   -c /home/newrt/Documents/cmake-test/build/CMakeFiles/CMakeTmp/testCCompiler.c
    Linking C executable cmTC_167cc
    /usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_167cc.dir/link.txt --verbose=1
    /opt/fsl-imx-x11/4.1.15-2.0.1/sysroots/x86_64-pokysdk-linux/usr/bin/arm-emtronix-linux-gnueabi/arm-emtronix-linux-gnueabi-gcc      -rdynamic CMakeFiles/cmTC_167cc.dir/testCCompiler.c.o  -o cmTC_167cc
    /opt/fsl-imx-x11/4.1.15-2.0.1/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-emtronix-linux-gnueabi/gcc/arm-emtronix-linux-gnueabi/5.3.0/real-ld: cannot find crt1.o: No such file or directory
    /opt/fsl-imx-x11/4.1.15-2.0.1/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-emtronix-linux-gnueabi/gcc/arm-emtronix-linux-gnueabi/5.3.0/real-ld: cannot find crti.o: No such file or directory
    /opt/fsl-imx-x11/4.1.15-2.0.1/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-emtronix-linux-gnueabi/gcc/arm-emtronix-linux-gnueabi/5.3.0/real-ld: cannot find crtbegin.o: No such file or directory
    /opt/fsl-imx-x11/4.1.15-2.0.1/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-emtronix-linux-gnueabi/gcc/arm-emtronix-linux-gnueabi/5.3.0/real-ld: cannot find -lgcc
    /opt/fsl-imx-x11/4.1.15-2.0.1/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-emtronix-linux-gnueabi/gcc/arm-emtronix-linux-gnueabi/5.3.0/real-ld: cannot find -lgcc_s
    /opt/fsl-imx-x11/4.1.15-2.0.1/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-emtronix-linux-gnueabi/gcc/arm-emtronix-linux-gnueabi/5.3.0/real-ld: cannot find -lc
    /opt/fsl-imx-x11/4.1.15-2.0.1/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-emtronix-linux-gnueabi/gcc/arm-emtronix-linux-gnueabi/5.3.0/real-ld: cannot find -lgcc
    /opt/fsl-imx-x11/4.1.15-2.0.1/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-emtronix-linux-gnueabi/gcc/arm-emtronix-linux-gnueabi/5.3.0/real-ld: cannot find -lgcc_s
    /opt/fsl-imx-x11/4.1.15-2.0.1/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-emtronix-linux-gnueabi/gcc/arm-emtronix-linux-gnueabi/5.3.0/real-ld: cannot find crtend.o: No such file or directory
    /opt/fsl-imx-x11/4.1.15-2.0.1/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-emtronix-linux-gnueabi/gcc/arm-emtronix-linux-gnueabi/5.3.0/real-ld: cannot find crtn.o: No such file or directory
    collect2: error: ld returned 1 exit status
    make[1]: *** [CMakeFiles/cmTC_167cc.dir/build.make:87��cmTC_167cc] ���� 1
    make[1]: �뿪Ŀ¼��/home/newrt/Documents/cmake-test/build/CMakeFiles/CMakeTmp��
    make: *** [Makefile:121��cmTC_167cc/fast] ���� 2


CMakeLists.txt 内容如下

project(hello)
add_executable(hello hello.cpp)

cross-compile.txt内容如下

#to set the toolpath variable
set(TOOLCHAIN_DIR "/opt/fsl-imx-x11/4.1.15-2.0.1/sysroots")
set(TOOLCHAIN_HOST "${TOOLCHAIN_DIR}/x86_64-pokysdk-linux/usr/bin/arm-emtronix-linux-gnueabi/arm-emtronix-linux-gnueabi")
set(TOOLCHAIN_INCLUDE
        "${TOOLCHAIN_DIR}/cortexa9hf-neon-emtronix-linux-gnueabi/usr/include"
        "${TOOLCHAIN_DIR}/cortexa9hf-neon-emtronix-linux-gnueabi/usr/include/c++/5.3.0"
   )
set(TOOLCHAIN_LIB
        "${TOOLCHAIN_DIR}/cortexa9hf-neon-emtronix-linux-gnueabi/lib"
        "${TOOLCHAIN_DIR}/cortexa9hf-neon-emtronix-linux-gnueabi/usr/lib/arm-emtronix-linux-gnueabi/5.3.0/"
        "${TOOLCHAIN_DIR}/cortexa9hf-neon-emtronix-linux-gnueabi/usr/lib"
   )
set(CMAKE_FIND_ROOT_PATH ${TOOLCHAIN_DIR}/cortexa9hf-neon-emtronix-linux-gnueabi)
#message("${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE}")


set(TOOLCHAIN_CC "${TOOLCHAIN_HOST}-gcc")
set(TOOLCHAIN_CXX "${TOOLCHAIN_HOST}-g++")

#to tell cmake it is crosscompileing
set(CMAKE_CROSSCOMPILING TRUE)

# Define name of the target system
set(CMAKE_SYSTEM_NAME "Linux")

# define the name of target architecture
set(CMAKE_SYSTEM_PROCESSOR arm)

# Define the compiler
set(CMAKE_C_COMPILER ${TOOLCHAIN_CC})
set(CMAKE_CXX_COMPILER ${TOOLCHAIN_CXX})

#to tell cmake where to search the header or lib files
#set(CMAKE_FIND_ROOT_PATH "${TOOLCHAIN_INCLUDE}" "${TOOLCHAIN_LIB}")
include_directories (
        ${TOOLCHAIN_DIR}/cortexa9hf-neon-emtronix-linux-gnueabi/include/c++/5.3.0
        ${TOOLCHAIN_DIR}/cortexa9hf-neon-emtronix-linux-gnueabi/usr/include
        )
set(CMAKE_INCLUDE_PATH
        ${TOOLCHAIN_INCLUDE} )
set(CMAKE_LIBRARY_PATH ${TOOLCHAIN_LIB} )

# search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

# for libraries and headers in the target directories
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
#set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

希望你们支持一下谢谢


  单帖管理 | 引用 | 回复 回到顶部
帅哥哟,离线,有人找我吗?
fumin
2楼 信息 | 搜索 | 邮箱


加好友 发短信
  发帖心情 Post By:2019-4-2 17:42:00   [只看该作者]

使用TI的交叉编译器

newrt@newrt-desktop:~/Documents/cmake-test/build$ cmake -DCMAKE_TOOLCHAIN_FILE=../cross-compile2.txt ..
-- The C compiler identification is GNU 6.2.1
-- The CXX compiler identification is GNU 6.2.1
-- Check for working C compiler: /opt/newrt/TKS/linux-devkit/sysroots/x86_64-arago-linux/usr/bin/arm-linux-gnueabihf-gcc
-- Check for working C compiler: /opt/newrt/TKS/linux-devkit/sysroots/x86_64-arago-linux/usr/bin/arm-linux-gnueabihf-gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /opt/newrt/TKS/linux-devkit/sysroots/x86_64-arago-linux/usr/bin/arm-linux-gnueabihf-g++
-- Check for working CXX compiler: /opt/newrt/TKS/linux-devkit/sysroots/x86_64-arago-linux/usr/bin/arm-linux-gnueabihf-g++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/newrt/Documents/cmake-test/build

没有问题。


  单帖管理 | 引用 | 回复 回到顶部
帅哥哟,离线,有人找我吗?
fumin
3楼 信息 | 搜索 | 邮箱


加好友 发短信
  发帖心情 Post By:2019-4-2 17:44:00   [只看该作者]

回到错误的问题点

》》》cannot find crt1.o: No such file or directory

发现在/opt/fsl-imx-x11/4.1.15-2.0.1/sysroots/cortexa9hf-neon-emtronix-linux-gnueabi/usr/lib/crt1.o。

那就是我哪里设置问题。但是cross-compile中该设的变量我都设置啦。那就奇怪了???

[此贴子已经被作者于2019-4-2 17:44:26编辑过]

  单帖管理 | 引用 | 回复 回到顶部
x10
4楼


  发帖心情 Post By:2019-4-4 23:02:00   [只看该作者]

黄工比较清楚,他在外出差。我会让他尽快看看。


  单帖管理 | 引用 | 回复 回到顶部
帅哥哟,离线,有人找我吗?
hzc
5楼 信息 | 搜索 | 邮箱


加好友 发短信 员工
  发帖心情 Post By:2019-4-4 23:42:00   [只看该作者]

你好,如果使用cmake编译的话,不需要对工具链做任何设置,所以cross-compile.txt是不需要的,只需要在CmakeList设置工程的名称,源文件等就行了。然后使用source命令加载工具链安装目录下的environment文件,就可以直接在工程中使用cmake .生成makefile了。


  单帖管理 | 引用 | 回复 回到顶部
帅哥哟,离线,有人找我吗?
fumin
6楼 信息 | 搜索 | 邮箱


加好友 发短信
  发帖心情 Post By:2019-4-9 16:23:00   [只看该作者]

非常感谢黄工的信息和相关帮助。按照上述描述问题解决。

[此贴子已经被作者于2019-4-9 16:23:20编辑过]

  单帖管理 | 引用 | 回复 回到顶部
帅哥哟,离线,有人找我吗?
hzc
7楼 信息 | 搜索 | 邮箱


加好友 发短信 员工
  发帖心情 Post By:2019-4-9 16:35:00   [只看该作者]

图片点击可在新窗口打开查看问题解决了就好


  单帖管理 | 引用 | 回复 回到顶部

返回首页

cmake交叉编译错误

用户名:
            验证码: 验证码,看不清楚?请点击刷新验证码
内容: