STD C++ not found in cross-compile sysroot

I am trying to use a Yocto cross-compile SDK with CLion. Such an SDK provides it's own sysroot. A script such as the following is provided to set up the environment variables for use with SDK:

export SDKTARGETSYSROOT=/opt/pokysdk/sysroots/cortexa7hf-neon-vfpv4-poky-linux-gnueabi
export PATH=/opt/pokysdk/sysroots/x86_64-pokysdk-linux/usr/bin:/opt/pokysdk/sysroots/x86_64-pokysdk-linux/usr/sbin:/opt/pokysdk/sysroots/x86_64-pokysdk-linux/bin:/opt/pokysdk/sysroots/x86_64-pokysdk-linux/sbin:/opt/pokysdk/sysroots/x86_64-pokysdk-linux/usr/bin/../x86_64-pokysdk-linux/bin:/opt/pokysdk/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-gnueabi:/opt/pokysdk/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-uclibc:/opt/pokysdk/sysroots/x86_64-pokysdk-linux/usr/bin/arm-poky-linux-musl:$PATH
export PKG_CONFIG_SYSROOT_DIR=$SDKTARGETSYSROOT
export PKG_CONFIG_PATH=$SDKTARGETSYSROOT/usr/lib/pkgconfig:$SDKTARGETSYSROOT/usr/share/pkgconfig
export CONFIG_SITE=/opt/pokysdk/site-config-cortexa7hf-neon-vfpv4-poky-linux-gnueabi
export OECORE_NATIVE_SYSROOT="/opt/pokysdk/sysroots/x86_64-pokysdk-linux"
export OECORE_TARGET_SYSROOT="$SDKTARGETSYSROOT"
export OECORE_ACLOCAL_OPTS="-I /opt/pokysdk/sysroots/x86_64-pokysdk-linux/usr/share/aclocal"
unset command_not_found_handle
export CC="arm-poky-linux-gnueabi-gcc  -march=armv7ve -marm -mfpu=neon-vfpv4  -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=$SDKTARGETSYSROOT"
export CXX="arm-poky-linux-gnueabi-g++  -march=armv7ve -marm -mfpu=neon-vfpv4  -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=$SDKTARGETSYSROOT"
export CPP="arm-poky-linux-gnueabi-gcc -E  -march=armv7ve -marm -mfpu=neon-vfpv4  -mfloat-abi=hard -mcpu=cortex-a7 --sysroot=$SDKTARGETSYSROOT"
export AS="arm-poky-linux-gnueabi-as "
export LD="arm-poky-linux-gnueabi-ld  --sysroot=$SDKTARGETSYSROOT"
export GDB=arm-poky-linux-gnueabi-gdb
export STRIP=arm-poky-linux-gnueabi-strip
export RANLIB=arm-poky-linux-gnueabi-ranlib
export OBJCOPY=arm-poky-linux-gnueabi-objcopy
export OBJDUMP=arm-poky-linux-gnueabi-objdump
export AR=arm-poky-linux-gnueabi-ar
export NM=arm-poky-linux-gnueabi-nm
export M4=m4
export TARGET_PREFIX=arm-poky-linux-gnueabi-
export CONFIGURE_FLAGS="--target=arm-poky-linux-gnueabi --host=arm-poky-linux-gnueabi --build=x86_64-linux --with-libtool-sysroot=$SDKTARGETSYSROOT"
export CFLAGS=" -O2 -pipe"
export CXXFLAGS="${BUILDSDK_CXXFLAGS}"
export LDFLAGS="-Wl,-O1"
export CPPFLAGS=""
export KCFLAGS="--sysroot=$SDKTARGETSYSROOT"
export OECORE_DISTRO_VERSION="2.3"
export OECORE_SDK_VERSION="2.3"
export ARCH=arm
export CROSS_COMPILE=arm-poky-linux-gnueabi-

# Append environment subscripts
if [ -d "$OECORE_TARGET_SYSROOT/environment-setup.d" ]; then
    for envfile in $OECORE_TARGET_SYSROOT/environment-setup.d/*.sh; do
        . $envfile
    done
fi
if [ -d "$OECORE_NATIVE_SYSROOT/environment-setup.d" ]; then
    for envfile in $OECORE_NATIVE_SYSROOT/environment-setup.d/*.sh; do
        . $envfile
    done
fi

I have tried to source this before launching CLion or by setting the variables with the menu in CLion. Both are sufficient to get my application to compile but the problem is that the IDE is not aware of the standard C++ library includes any more. It for instance complains that it cannot find iostream. Other libraries included in the sysroot and imported with CMake work perfectly though.

The SDK also provides a CMake toolcahin file but it does not seem to make any difference, it is as follows:

set( CMAKE_SYSTEM_NAME Linux )
set( CMAKE_C_FLAGS $ENV{CFLAGS} CACHE STRING "" FORCE )
set( CMAKE_CXX_FLAGS $ENV{CXXFLAGS}  CACHE STRING "" FORCE )
set( CMAKE ASM_FLAGS ${CMAKE_C_FLAGS} CACHE STRING "" FORCE )
set( CMAKE_LDFLAGS_FLAGS ${CMAKE_CXX_FLAGS} CACHE STRING "" FORCE )

set( CMAKE_FIND_ROOT_PATH $ENV{OECORE_TARGET_SYSROOT} $ENV{OECORE_NATIVE_SYSROOT} )
set( CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER )
set( CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY )
set( CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY )
set( CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY )

# Set CMAKE_SYSTEM_PROCESSOR from the sysroot name (assuming processor-distro-os).
if ($ENV{SDKTARGETSYSROOT} MATCHES "/sysroots/([a-zA-Z0-9_-]+)-.+-.+")
  set(CMAKE_SYSTEM_PROCESSOR ${CMAKE_MATCH_1})
endif()

# Include the toolchain configuration subscripts
file( GLOB toolchain_config_files "${CMAKE_TOOLCHAIN_FILE}.d/*.cmake" )
foreach(config ${toolchain_config_files})
    include(${config})
endforeach()

I would really love to use CLion for this project as CMake clearly supports the SDK.

1
6 comments

I have exactly the same question!

0
Avatar
Permanently deleted user

I believe with current CLion limitations it's all down to configuration in CMakeLists.txt or cmake-toolchains. If you specify value(s) for CMAKE_SYSROOT variable, it should probably do the thing, however for me it didn't work in CLion 2017.2 (although I'm using trial version).

CLion managed to find C++ installed in my system and seems to use it when resolving C++ headers. There is no setting I can adjust to use anything else. Sadly, "Languages & Frameworks / C/C++" page in settings is not very rich.

0

Solution: Passing --sysroot to CMAKE_CXX_FLAGS has fixed it for us.

2

Juan, could you please share your fixed version of toolchain file?

0

Transfer:

set( CMAKE_CXX_FLAGS $ENV{CXXFLAGS} CACHE STRING "" FORCE )

To:
set(MYSYSROOT /path/to/sysroots/cortexa8hf-neon-example-linux-gnueabi )
set( CMAKE_CXX_FLAGS "--sysroot=${MYSYSROOT} $ENV{CXXFLAGS}" CACHE STRING "" FORCE )

 

 

0

Please sign in to leave a comment.