Yocto Hello World C ++ CMake Project无法编译简单的测试程序

时间:2019-04-12 08:15:09

标签: eclipse cmake yocto bitbake

我无法使用Yocto插件在Eclipse中构建简单的Hello World C ++ CMake项目。 Yocto的版本是“ thud”。

local.conf包含以下行:

TOOLCHAIN_HOST_TASK_append += " nativesdk-cmake"

我已经构建了SDK

bitbake myBoard -c populate_sdk

我已经安装了sdk,获取了环境设置,从同一终端启动了eclipse,并配置了yocto插件。

环境脚本具有以下变量:

export SDKTARGETSYSROOT=/yocto/sdk/myBoard/sysroots/armv7at2hf-neon-fslc-linux-gnueabi
export CC="arm-fslc-linux-gnueabi-gcc  -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard --sysroot=$SDKTARGETSYSROOT"
export CXX="arm-fslc-linux-gnueabi-g++  -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard --sysroot=$SDKTARGETSYSROOT"
export CPP="arm-fslc-linux-gnueabi-gcc -E  -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard --sysroot=$SDKTARGETSYSROOT"

当我尝试构建时,我将得到以下输出(甚至采购sdk的环境设置,然后从命令行进行cmake):

$ cmake ..
-- The C compiler identification is GNU 8.2.0
-- The CXX compiler identification is GNU 8.2.0
-- Check for working C compiler: /yocto/sdk/myBoard/sysroots/x86_64-fslcsdk-linux/usr/bin/arm-fslc-linux-gnueabi/arm-fslc-linux-gnueabi-gcc
-- Check for working C compiler: /yocto/sdk/myBoard/sysroots/x86_64-fslcsdk-linux/usr/bin/arm-fslc-linux-gnueabi/arm-fslc-linux-gnueabi-gcc -- broken
CMake Error at /yocto/sdk/myBoard/sysroots/x86_64-fslcsdk-linux/usr/share/cmake-3.12/Modules/CMakeTestCCompiler.cmake:52 (message):
  The C compiler

    "/yocto/sdk/myBoard/sysroots/x86_64-fslcsdk-linux/usr/bin/arm-fslc-linux-gnueabi/arm-fslc-linux-gnueabi-gcc"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: /yocto/eclipse-ws/prova/Debug/CMakeFiles/CMakeTmp

    Run Build Command:"/yocto/sdk/myBoard/sysroots/armv7at2hf-neon-fslc-linux-gnueabi/usr/bin/make" "cmTC_4df0b/fast"
    /yocto/sdk/myBoard/sysroots/armv7at2hf-neon-fslc-linux-gnueabi/usr/bin/make: 1: /yocto/sdk/myBoard/sysroots/armv7at2hf-neon-fslc-linux-gnueabi/usr/bin/make: Syntax error: word unexpected (expecting ")")


  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:4 (PROJECT)


-- Configuring incomplete, errors occurred!
See also "/yocto/eclipse-ws/prova/Debug/CMakeFiles/CMakeOutput.log".
See also "/yocto/eclipse-ws/prova/Debug/CMakeFiles/CMakeError.log".

有人看到导致错误的错误或遗漏吗?

在此先感谢您的帮助

更新
CMakeOutput.log显示:

The system is: Linux - 4.15.0-47-generic - x86_64
Compiling the C compiler identification source file "CMakeCCompilerId.c" succeeded.
Compiler: /yocto/sdk/myBoard/sysroots/x86_64-fslcsdk-linux/usr/bin/arm-fslc-linux-gnueabi/arm-fslc-linux-gnueabi-gcc 
Build flags: ;;;--sysroot=/yocto/sdk/myBoard/sysroots/armv7at2hf-neon-fslc-linux-gnueabi;;-march=armv7-a;-mthumb;-mfpu=neon;-mfloat-abi=hard;
Id flags:  

The output was:
0


Compilation of the C compiler identification source "CMakeCCompilerId.c" produced "a.out"

The C compiler identification is GNU, found in "/yocto/eclipse-ws/prova/Debug/CMakeFiles/3.12.2/CompilerIdC/a.out"

Compiling the CXX compiler identification source file "CMakeCXXCompilerId.cpp" succeeded.
Compiler: /yocto/sdk/myBoard/sysroots/x86_64-fslcsdk-linux/usr/bin/arm-fslc-linux-gnueabi/arm-fslc-linux-gnueabi-g++ 
Build flags: ;;;--sysroot=/yocto/sdk/myBoard/sysroots/armv7at2hf-neon-fslc-linux-gnueabi;;-march=armv7-a;-mthumb;-mfpu=neon;-mfloat-abi=hard;;-fpermissive
Id flags:  

The output was:
0

Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" produced "a.out"

The CXX compiler identification is GNU, found in "/yocto/eclipse-ws/prova/Debug/CMakeFiles/3.12.2/CompilerIdCXX/a.out"

更新2
如果我从Debug文件夹中删除所有内容并从命令行运行cmake,我将获得成功,甚至可以在Eclipse中进行构建。如果我更改CMakeLists.txt中的内容,则会再次显示该错误。

当通过eclipse或通过命令行生成Debug / CMakeFiles / 3.12.2 / CMakeSystem.cmake时,我会发现它们与众不同:

Eclipse

set(CMAKE_HOST_SYSTEM "Linux-4.15.0-47-generic")
set(CMAKE_HOST_SYSTEM_NAME "Linux")
set(CMAKE_HOST_SYSTEM_VERSION "4.15.0-47-generic")
set(CMAKE_HOST_SYSTEM_PROCESSOR "x86_64")

include("/yocto/eclipse-ws/prova/toolchain.cmake")

set(CMAKE_SYSTEM "Linux-4.15.0-47-generic")
set(CMAKE_SYSTEM_NAME "Linux")
set(CMAKE_SYSTEM_VERSION "4.15.0-47-generic")
set(CMAKE_SYSTEM_PROCESSOR "x86_64")

set(CMAKE_CROSSCOMPILING "FALSE")

set(CMAKE_SYSTEM_LOADED 1)

命令行

set(CMAKE_HOST_SYSTEM "Linux-4.15.0-47-generic")
set(CMAKE_HOST_SYSTEM_NAME "Linux")
set(CMAKE_HOST_SYSTEM_VERSION "4.15.0-47-generic")
set(CMAKE_HOST_SYSTEM_PROCESSOR "x86_64")

include("/yocto/sdk/aw70pc_am8000/sysroots/x86_64-fslcsdk-linux/usr/share/cmake/OEToolchainConfig.cmake")

set(CMAKE_SYSTEM "Linux")
set(CMAKE_SYSTEM_NAME "Linux")
set(CMAKE_SYSTEM_VERSION "")
set(CMAKE_SYSTEM_PROCESSOR "armv7at2hf-neon-fslc")

set(CMAKE_CROSSCOMPILING "TRUE")

set(CMAKE_SYSTEM_LOADED 1)

据我了解,eclipse插件正在生成一个配置,该配置使用arm工具链来编译测试程序,而不是交叉编译,并且显然失败了。命令行中的Cmake会以正确的方式生成它,但是它会被Eclipse的第一次更改所覆盖。

这是danlor要求的printenv

ARCH=arm
CONFIG_SITE=/yocto/sdk/myBoard/site-config-armv7at2hf-neon-fslc-linux-gnueabi
SDKTARGETSYSROOT=/yocto/sdk/myBoard/sysroots/armv7at2hf-neon-fslc-linux-gnueabi
CFLAGS= -O2 -pipe -g -feliminate-unused-debug-types 
KCFLAGS=--sysroot=/yocto/sdk/myBoard/sysroots/armv7at2hf-neon-fslc-linux-gnueabi
OECORE_ACLOCAL_OPTS=-I /yocto/sdk/myBoard/sysroots/x86_64-fslcsdk-linux/usr/share/aclocal
CC=arm-fslc-linux-gnueabi-gcc  -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard --sysroot=/yocto/sdk/myBoard/sysroots/armv7at2hf-neon-fslc-linux-gnueabi
OECORE_DISTRO_VERSION=2.6
OECORE_SDK_VERSION=2.6.1
PKG_CONFIG_SYSROOT_DIR=/yocto/sdk/myBoard/sysroots/armv7at2hf-neon-fslc-linux-gnueabi
CXXFLAGS= -O2 -pipe -g -feliminate-unused-debug-types 
STRIP=arm-fslc-linux-gnueabi-strip
OBJCOPY=arm-fslc-linux-gnueabi-objcopy
CONFIGURE_FLAGS=--target=arm-fslc-linux-gnueabi --host=arm-fslc-linux-gnueabi --build=x86_64-linux --with-libtool-sysroot=/yocto/sdk/myBoard/sysroots/armv7at2hf-neon-fslc-linux-gnueabi
OECORE_NATIVE_SYSROOT=/yocto/sdk/myBoard/sysroots/x86_64-fslcsdk-linux
RANLIB=arm-fslc-linux-gnueabi-ranlib
OBJDUMP=arm-fslc-linux-gnueabi-objdump
AS=arm-fslc-linux-gnueabi-as 
AR=arm-fslc-linux-gnueabi-ar
TARGET_PREFIX=arm-fslc-linux-gnueabi-
NM=arm-fslc-linux-gnueabi-nm
CXX=arm-fslc-linux-gnueabi-g++  -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard --sysroot=/yocto/sdk/myBoard/sysroots/armv7at2hf-neon-fslc-linux-gnueabi
OECORE_TARGET_OS=linux-gnueabi
OECORE_TARGET_ARCH=arm
OECORE_TARGET_SYSROOT=/yocto/sdk/myBoard/sysroots/armv7at2hf-neon-fslc-linux-gnueabi
CROSS_COMPILE=arm-fslc-linux-gnueabi-
OE_CMAKE_TOOLCHAIN_FILE=/yocto/sdk/myBoard/sysroots/x86_64-fslcsdk-linux/usr/share/cmake/OEToolchainConfig.cmake
CPPFLAGS=
LDFLAGS=-Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed
OE_CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX=
OECORE_BASELIB=lib
PKG_CONFIG_PATH=/yocto/sdk/myBoard/sysroots/armv7at2hf-neon-fslc-linux-gnueabi/usr/lib/pkgconfig:/yocto/sdk/myBoard/sysroots/armv7at2hf-neon-fslc-linux-gnueabi/usr/share/pkgconfig
CPP=arm-fslc-linux-gnueabi-gcc -E  -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard --sysroot=/yocto/sdk/myBoard/sysroots/armv7at2hf-neon-fslc-linux-gnueabi
LD=arm-fslc-linux-gnueabi-ld  --sysroot=/yocto/sdk/myBoard/sysroots/armv7at2hf-neon-fslc-linux-gnueabi

toolchain.cmake

# CMake system name must be something like "Linux".
# This is important for cross-compiling.
set(CMAKE_SYSTEM_PROCESSOR )
set(CMAKE_C_COMPILER arm-fslc-linux-gnueabi-gcc)
set(CMAKE_CXX_COMPILER arm-fslc-linux-gnueabi-g++)
set(CMAKE_C_FLAGS "   --sysroot=/yocto/sdk/myBoard/sysroots/armv7at2hf-neon-fslc-linux-gnueabi  -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard " CACHE STRING "CFLAGS")
set(CMAKE_CXX_FLAGS "   --sysroot=/yocto/sdk/myBoard/sysroots/armv7at2hf-neon-fslc-linux-gnueabi  -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard  -fpermissive" CACHE STRING "CXXFLAGS")
set(CMAKE_C_FLAGS_RELEASE "  --sysroot=/yocto/sdk/myBoard/sysroots/armv7at2hf-neon-fslc-linux-gnueabi  -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard  -DNDEBUG" CACHE STRING "CFLAGS for release")
set(CMAKE_CXX_FLAGS_RELEASE "  --sysroot=/yocto/sdk/myBoard/sysroots/armv7at2hf-neon-fslc-linux-gnueabi  -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard  -DNDEBUG" CACHE STRING "CXXFLAGS for release")
set(CMAKE_C_LINK_FLAGS "" CACHE STRING "LDFLAGS")
set(CMAKE_CXX_LINK_FLAGS "" CACHE STRING "LDFLAGS")

# only search in the paths provided so cmake doesnt pick
# up libraries and tools from the native build machine
set(CMAKE_FIND_ROOT_PATH /yocto/sdk/myBoard/sysroots/x86_64-fslcsdk-linux /yocto/sdk/myBoard/sysroots/armv7at2hf-neon-fslc-linux-gnueabi )
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)

# Use qt.conf settings
set(ENV{QT_CONF_PATH} qt.conf)

# We need to set the rpath to the correct directory as cmake does not provide any
# directory as rpath by default
set(CMAKE_INSTALL_RPATH )

# Use native cmake modules
set(CMAKE_MODULE_PATH /cmake/Modules/)

# add for non /usr/lib libdir, e.g. /usr/lib64
set(CMAKE_LIBRARY_PATH ${libdir} ${base_libdir})

解决方法

我找到了出路

在CMakeLists.txt中添加以下两行将告诉cmake编译器有效且不对其进行测试
SET(CMAKE_C_COMPILER_WORKS 1)
设置(CMAKE_CXX_COMPILER_WORKS 1)

现在,我可以成功构建自己的程序了,它就像一个魅力。
这意味着Eclipse可以交叉编译我的程序,但是当检查系统时,它将以另一种方式构建测试程序。

1 个答案:

答案 0 :(得分:0)

似乎您正在尝试使用交叉编译的make工具(为您的TARGET编译的工具,即/ yocto / sdk / myBoard / sysroots / armv7at2hf-neon-fslc-linux-gnueabi / usr / bin / make),而不是HOST make工具(/ yocto / sdk / myBoard / sysroots / x86_64-fslcsdk-linux / usr / bin / make)。更改它,然后重试:)