Problem with CXX (rust&cpp interopt) and yocto toolchain

Hello.

I have a problem with cxx for arm-linux (yocto toolchain) - fatal error: algorithm: No such file or directory .
I run cargo from cmake in C++ project . First time is fail always. Second time is Ok.
Why?

The first running:

     Running `/home/gitlab-runner/builds/0ac0fd1f/0/eprotect-platfrom/ecp/Model/protocol-model/protocol-model-rs/target/debug/build/cxx-11fa34c3f8e22089/build-script-build`
The following warnings were emitted during compilation:
warning: In file included from src/cxx.cc:1:
warning: src/../include/cxx.h:2:10: fatal error: algorithm: No such file or directory
warning:     2 | #include <algorithm>
warning:       |          ^~~~~~~~~~~
warning: compilation terminated.
error: failed to run custom build command for `cxx v1.0.56`
Caused by:
  process didn't exit successfully: `/home/gitlab-runner/builds/0ac0fd1f/0/eprotect-platfrom/ecp/Model/protocol-model/protocol-model-rs/target/debug/build/cxx-11fa34c3f8e22089/build-script-build` (exit code: 1)
  --- stdout
  TARGET = Some("arm-unknown-linux-gnueabihf")
  OPT_LEVEL = Some("0")
  HOST = Some("x86_64-unknown-linux-gnu")
  CXX_arm-unknown-linux-gnueabihf = None
  CXX_arm_unknown_linux_gnueabihf = None
  TARGET_CXX = None
  CXX = Some("/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/bin/arm-etos-linux-gnueabi/arm-etos-linux-gnueabi-g++")
  CXXFLAGS_arm-unknown-linux-gnueabihf = None
  CXXFLAGS_arm_unknown_linux_gnueabihf = None
  TARGET_CXXFLAGS = None
  CXXFLAGS = Some(" -O2 -pipe -g -feliminate-unused-debug-types ")
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = None
  CXX_arm-unknown-linux-gnueabihf = None
  CXX_arm_unknown_linux_gnueabihf = None
  TARGET_CXX = None
  CXX = Some("/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/bin/arm-etos-linux-gnueabi/arm-etos-linux-gnueabi-g++")
  CXXFLAGS_arm-unknown-linux-gnueabihf = None
  CXXFLAGS_arm_unknown_linux_gnueabihf = None
  TARGET_CXXFLAGS = None
  CXXFLAGS = Some(" -O2 -pipe -g -feliminate-unused-debug-types ")
  CRATE_CC_NO_DEFAULTS = None
  CARGO_CFG_TARGET_FEATURE = None
  running: "/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/bin/arm-etos-linux-gnueabi/arm-etos-linux-gnueabi-g++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-march=armv6" "-marm" "-mfpu=vfp" "-O2" "-pipe" "-g" "-feliminate-unused-debug-types" "-o" "/home/gitlab-runner/builds/0ac0fd1f/0/eprotect-platfrom/ecp/Model/protocol-model/protocol-model-rs/target/arm-unknown-linux-gnueabihf/debug/build/cxx-eddaf1818d68777b/out/src/cxx.o" "-c" "src/cxx.cc"
  cargo:warning=In file included from src/cxx.cc:1:
  cargo:warning=src/../include/cxx.h:2:10: fatal error: algorithm: No such file or directory
  cargo:warning=    2 | #include <algorithm>
  cargo:warning=      |          ^~~~~~~~~~~
  cargo:warning=compilation terminated.
  exit code: 1
  --- stderr
  error occurred: Command "/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/bin/arm-etos-linux-gnueabi/arm-etos-linux-gnueabi-g++" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-march=armv6" "-marm" "-mfpu=vfp" "-O2" "-pipe" "-g" "-feliminate-unused-debug-types" "-o" "/home/gitlab-runner/builds/0ac0fd1f/0/eprotect-platfrom/ecp/Model/protocol-model/protocol-model-rs/target/arm-unknown-linux-gnueabihf/debug/build/cxx-eddaf1818d68777b/out/src/cxx.o" "-c" "src/cxx.cc" with args "arm-etos-linux-gnueabi-g++" did not execute successfully (status code exit code: 1).
warning: build failed, waiting for other jobs to finish...
error: build failed

I suspect the "fails only the first time" thing may be "fails every time, but cmake doesn't track failures correctly and skips the command".

It looks like your sysroot for cross-compilation doesn't have C++ headers?

If you run this:

"/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/bin/arm-etos-linux-gnueabi/arm-etos-linux-gnueabi-g++"  -xc++ -E -v -

do any of the directories it prints contain algorithm?

I have:

ignoring nonexistent directory "/not/exist/usr/include/c++/9.3.0"
ignoring nonexistent directory "/not/exist/usr/include/c++/9.3.0/arm-etos-linux-gnueabi"
ignoring nonexistent directory "/not/exist/usr/include/c++/9.3.0/backward"
ignoring nonexistent directory "/not/exist/usr/lib/arm-etos-linux-gnueabi/9.3.0/include"
ignoring nonexistent directory "/not/exist/usr/local/include"
ignoring nonexistent directory "/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/lib/arm-etos-linux-gnueabi/gcc/arm-etos-linux-gnueabi/9.3.0/../../../../../arm-etos-linux-gnueabi/include"
ignoring nonexistent directory "/not/exist/usr/include/"

full log:

gitlab-runner@imager:~/builds/0ac0fd1f/0/eprotect-platfrom/ecp/build-etos$ /opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/bin/arm-etos-linux-gnueabi/arm-etos-linux-gnueabi-g++  -xc++ -E -v -
Using built-in specs.
COLLECT_GCC=/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/bin/arm-etos-linux-gnueabi/arm-etos-linux-gnueabi-g++
Target: arm-etos-linux-gnueabi
Configured with: ../../../../../../work-shared/gcc-9.3.0-r0/gcc-9.3.0/configure --build=x86_64-linux --host=x86_64-etossdk-linux --target=arm-etos-linux-gnueabi --prefix=/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr --exec_prefix=/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr --bindir=/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/bin/arm-etos-linux-gnueabi --sbindir=/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/bin/arm-etos-linux-gnueabi --libexecdir=/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/libexec/arm-etos-linux-gnueabi --datadir=/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/share --sysconfdir=/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/etc --sharedstatedir=/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/com --localstatedir=/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/var --libdir=/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/lib/arm-etos-linux-gnueabi --includedir=/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/include --oldincludedir=/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/include --infodir=/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/share/info --mandir=/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/share/man --disable-silent-rules --disable-dependency-tracking --with-libtool-sysroot=/home/mslomiany/linux-dev/dunfell/build/tmp/work/x86_64-nativesdk-etossdk-linux/gcc-cross-canadian-arm/9.3.0-r0/recipe-sysroot --with-gnu-ld --enable-shared --enable-languages=c,c++ --enable-threads=posix --enable-multilib --enable-c99 --enable-long-long --enable-symvers=gnu --enable-libstdcxx-pch --program-prefix=arm-etos-linux-gnueabi- --without-local-prefix --disable-install-libiberty --enable-lto --disable-libssp --enable-libitm --disable-bootstrap --disable-libmudflap --with-system-zlib --with-linker-hash-style=gnu --enable-linker-build-id --with-ppl=no --with-cloog=no --enable-checking=release --enable-cheaders=c_global --without-isl --with-gxx-include-dir=/not/exist/usr/include/c++/9.3.0 --with-build-time-tools=/home/mslomiany/linux-dev/dunfell/build/tmp/work/x86_64-nativesdk-etossdk-linux/gcc-cross-canadian-arm/9.3.0-r0/recipe-sysroot-native/usr/arm-etos-linux-gnueabi/bin --with-sysroot=/not/exist --with-build-sysroot=/home/mslomiany/linux-dev/dunfell/build/tmp/work/x86_64-nativesdk-etossdk-linux/gcc-cross-canadian-arm/9.3.0-r0/recipe-sysroot --enable-poison-system-directories --disable-static --enable-nls --with-glibc-version=2.28 --enable-initfini-array
Thread model: posix
gcc version 9.3.0 (GCC) 
COLLECT_GCC_OPTIONS='-E' '-v' '-shared-libgcc' '-mcpu=arm10tdmi' '-mtls-dialect=gnu' '-marm' '-march=armv5t'
 /opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/libexec/arm-etos-linux-gnueabi/gcc/arm-etos-linux-gnueabi/9.3.0/cc1plus -E -quiet -v -D_GNU_SOURCE - -mcpu=arm10tdmi -mtls-dialect=gnu -marm -march=armv5t
ignoring nonexistent directory "/not/exist/usr/include/c++/9.3.0"
ignoring nonexistent directory "/not/exist/usr/include/c++/9.3.0/arm-etos-linux-gnueabi"
ignoring nonexistent directory "/not/exist/usr/include/c++/9.3.0/backward"
ignoring nonexistent directory "/not/exist/usr/lib/arm-etos-linux-gnueabi/9.3.0/include"
ignoring nonexistent directory "/not/exist/usr/local/include"
ignoring nonexistent directory "/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/lib/arm-etos-linux-gnueabi/gcc/arm-etos-linux-gnueabi/9.3.0/../../../../../arm-etos-linux-gnueabi/include"
ignoring nonexistent directory "/not/exist/usr/include/"
#include "..." search starts here:
#include <...> search starts here:
 /opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/lib/arm-etos-linux-gnueabi/gcc/arm-etos-linux-gnueabi/9.3.0/include
 /opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/lib/arm-etos-linux-gnueabi/gcc/arm-etos-linux-gnueabi/9.3.0/include-fixed
End of search list.

printenv:

OE_QMAKE_QDBUSCPP2XML=/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/bin/qdbuscpp2xml
ARCH=arm
LESSCLOSE=/usr/bin/lesspipe %s %s
OE_QMAKE_INCDIR_QT=/opt/etos/3.1.1/sysroots/armv7at2hf-neon-etos-linux-gnueabi/usr/include
GDB=arm-etos-linux-gnueabi-gdb
LANG=en_US.UTF-8
OPENSSL_CONF=/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/lib/ssl-1.1/openssl.cnf
SUDO_GID=1004
OLDPWD=/home/gitlab-runner/builds/0ac0fd1f/0/eprotect-platfrom/ecp
CONFIG_SITE=/opt/etos/3.1.1/site-config-armv7at2hf-neon-etos-linux-gnueabi
OE_QMAKE_RCC=/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/bin/rcc
QT_CONF_PATH=/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/bin/qt.conf
SDKTARGETSYSROOT=/opt/etos/3.1.1/sysroots/armv7at2hf-neon-etos-linux-gnueabi
USERNAME=root
SUDO_COMMAND=/bin/su gitlab-runner
CFLAGS= -O2 -pipe -g -feliminate-unused-debug-types 
M4=m4
OE_QMAKE_AR=arm-etos-linux-gnueabi-ar
KCFLAGS=--sysroot=/opt/etos/3.1.1/sysroots/armv7at2hf-neon-etos-linux-gnueabi
OECORE_ACLOCAL_OPTS=-I /opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/share/aclocal
CC=arm-etos-linux-gnueabi-gcc  -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard --sysroot=/opt/etos/3.1.1/sysroots/armv7at2hf-neon-etos-linux-gnueabi
READELF=arm-etos-linux-gnueabi-readelf
OECORE_DISTRO_VERSION=3.1.1
OECORE_SDK_VERSION=3.1.1
USER=gitlab-runner
PKG_CONFIG_SYSROOT_DIR=/opt/etos/3.1.1/sysroots/armv7at2hf-neon-etos-linux-gnueabi
CXXFLAGS= -O2 -pipe -g -feliminate-unused-debug-types 
OE_QMAKE_UIC=/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/bin/uic
STRIP=arm-etos-linux-gnueabi-strip
OBJCOPY=arm-etos-linux-gnueabi-objcopy
OE_QMAKE_PATH_HOST_BINS=/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/bin
PWD=/home/gitlab-runner/builds/0ac0fd1f/0/eprotect-platfrom/ecp/build-etos
CONFIGURE_FLAGS=--target=arm-etos-linux-gnueabi --host=arm-etos-linux-gnueabi --build=x86_64-linux --with-libtool-sysroot=/opt/etos/3.1.1/sysroots/armv7at2hf-neon-etos-linux-gnueabi
OE_QMAKE_QT_CONFIG=/opt/etos/3.1.1/sysroots/armv7at2hf-neon-etos-linux-gnueabi/usr/lib/mkspecs/qconfig.pri
HOME=/home/gitlab-runner
SUDO_USER=mhanusek
OECORE_NATIVE_SYSROOT=/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux
RANLIB=arm-etos-linux-gnueabi-ranlib
OBJDUMP=arm-etos-linux-gnueabi-objdump
AS=arm-etos-linux-gnueabi-as 
AR=arm-etos-linux-gnueabi-ar
OE_QMAKE_QDBUSXML2CPP=/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/bin/qdbusxml2cpp
TARGET_PREFIX=arm-etos-linux-gnueabi-
OE_QMAKE_CXX=arm-etos-linux-gnueabi-g++  -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard --sysroot=/opt/etos/3.1.1/sysroots/armv7at2hf-neon-etos-linux-gnueabi
OE_QMAKE_STRIP=arm-etos-linux-gnueabi-strip
OE_QMAKE_CC=arm-etos-linux-gnueabi-gcc  -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard --sysroot=/opt/etos/3.1.1/sysroots/armv7at2hf-neon-etos-linux-gnueabi
OE_QMAKE_MOC=/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/bin/moc
OE_QMAKE_CFLAGS= -O2 -pipe -g -feliminate-unused-debug-types 
OE_QMAKE_LIBDIR_QT=/opt/etos/3.1.1/sysroots/armv7at2hf-neon-etos-linux-gnueabi/usr/lib
NM=arm-etos-linux-gnueabi-nm
SUDO_UID=1003
MAIL=/var/mail/gitlab-runner
OE_QMAKE_LINK=arm-etos-linux-gnueabi-g++  -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard --sysroot=/opt/etos/3.1.1/sysroots/armv7at2hf-neon-etos-linux-gnueabi
CXX=arm-etos-linux-gnueabi-g++  -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard --sysroot=/opt/etos/3.1.1/sysroots/armv7at2hf-neon-etos-linux-gnueabi
OECORE_TARGET_OS=linux-gnueabi
SHELL=/bin/bash
TERM=xterm-256color
OE_QMAKE_CXXFLAGS= -O2 -pipe -g -feliminate-unused-debug-types 
QMAKESPEC=/opt/etos/3.1.1/sysroots/armv7at2hf-neon-etos-linux-gnueabi/usr/lib/mkspecs/linux-oe-g++
OECORE_TARGET_ARCH=arm
OECORE_TARGET_SYSROOT=/opt/etos/3.1.1/sysroots/armv7at2hf-neon-etos-linux-gnueabi
SHLVL=1
CROSS_COMPILE=arm-etos-linux-gnueabi-
OE_QMAKE_LDFLAGS=-Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed
OE_CMAKE_TOOLCHAIN_FILE=/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/share/cmake/OEToolchainConfig.cmake
CPPFLAGS=
LOGNAME=gitlab-runner
LDFLAGS=-Wl,-O1 -Wl,--hash-style=gnu -Wl,--as-needed
OE_CMAKE_FIND_LIBRARY_CUSTOM_LIB_SUFFIX=
PATH=/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/bin:/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/bin:/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/sbin:/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/bin:/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/sbin:/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/bin/../x86_64-etossdk-linux/bin:/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/bin/arm-etos-linux-gnueabi:/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/bin/arm-etos-linux-musl:/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/bin:/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/bin:/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/sbin:/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/bin:/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/sbin:/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/bin/../x86_64-etossdk-linux/bin:/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/bin/arm-etos-linux-gnueabi:/opt/etos/3.1.1/sysroots/x86_64-etossdk-linux/usr/bin/arm-etos-linux-musl:/home/gitlab-runner/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin
OECORE_BASELIB=lib
PKG_CONFIG_PATH=/opt/etos/3.1.1/sysroots/armv7at2hf-neon-etos-linux-gnueabi/usr/lib/pkgconfig:/opt/etos/3.1.1/sysroots/armv7at2hf-neon-etos-linux-gnueabi/usr/share/pkgconfig
CPP=arm-etos-linux-gnueabi-gcc -E  -march=armv7-a -mthumb -mfpu=neon -mfloat-abi=hard --sysroot=/opt/etos/3.1.1/sysroots/armv7at2hf-neon-etos-linux-gnueabi
LD=arm-etos-linux-gnueabi-ld  --sysroot=/opt/etos/3.1.1/sysroots/armv7at2hf-neon-etos-linux-gnueabi
LESSOPEN=| /usr/bin/lesspipe %s
_=/usr/bin/printenv

These non-existent directories seem like the problem, especially:

So your arm-etos-linux-gnueabi cross-compiler installation is incomplete, and without that include directory isn't going to work.

See if there's another package that you need to install, or if the arm-etos-linux-gnueabi/include directory exists somewhere else, and move it to where the compiler expects it.

2 Likes

Thanks for your reply.
I'm wondering...
I should pass the environment's variable SYSROOT in the file - build.rs:

fn main() {
    let _build = cxx_build::bridge("src/bindings.rs");
    println!("cargo:rerun-if-changed=src/bindings.rs");
}

or by RUSTFLAGS?

I solved it.
export CXXFLAGS="$CXXFLAGS -mfloat-abi=hard --sysroot /opt/etos/3.1.1/sysroots/armv7at2hf-neon-etos-linux-gnueabi"

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.