'crosscompile: undefined reference to std::__atomic_futex_unsigned_base::_M_futex_notify_all(unsigned int*) when linking

I want to crosscompile tiny-dnn(a c++14 project, https://github.com/tiny-dnn/tiny-dnn ) on arm platform. so I installed g++-arm-Linux-gnueabi and gcc-arm-Linux-gnueabi, the version is GCC5.4. Then I modified the CMakeList to add some flags.

option(ARM "Crosscompile with arm" ON)
if(ARM)
SET(CMAKE_SYSTEM_NAME Linux)
SET(CMAKE_C_COMPILER arm-linux-gnueabi-gcc)
SET(CMAKE_CXX_COMPILER arm-linux-gnueabi-g++)
SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
endif()

Then I added some flags:

-march=armv7-a -mtune=cortex-a9 -mfpu=neon

finally, all the flags(some flags show twice) are:

-O3 -DNDEBUG -O3 -march=armv7-a -mtune=cortex-a9 -mfpu=neon -static-libstdc++ -static-libgcc -static -pthread -Wall -Wpedantic -Wno-narrowing -Wno-deprecated -Wall -Wpedanitc -Wno-narrowing -Wno-deprecated

finally I have got these error:

[ 6%] Building CXX object examples/CMakeFiles/example_mnist_train.dir/mnist/train.cpp.o [ 12%] Linking CXX executable example_mnist_train CMakeFiles/example_mnist_train.dir/mnist/train.cpp.o: In function std::__future_base::_State_baseV2::_M_set_result(std::function ()>, bool) [clone .constprop.5599]': train.cpp:(.text+0x584): undefined reference tostd::__atomic_futex_unsigned_base::_M_futex_notify_all(unsigned int*)' CMakeFiles/example_mnist_train.dir/mnist/train.cpp.o: In function std::__future_base::_State_baseV2::_M_set_result(std::function ()>, bool) [clone .constprop.5600]': train.cpp:(.text+0x67c): undefined reference tostd::__atomic_futex_unsigned_base::_M_futex_notify_all(unsigned int*)' CMakeFiles/example_mnist_train.dir/mnist/train.cpp.o: In function `std::__future_base::_Result::~_Result()':

...etc

It seems that it can't refer to the std lib. Did I miss something?

BTW, I can compile the project on both Nvidia TX1 and Raspbian Pi, so the project should be compatible with ARM.



Solution 1:[1]

Check how was your gcc compiled using gcc -v. If architecture required via -march flag used by your project does not match --with-arch value used for gcc compilation, it may cause issues similar to one you are referring to.

In that case, you may need to get another toolchain and runtime for your platform.

gcc -v will give output similar to the one below, check the --with-arch flag in Configured with section:

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
OFFLOAD_TARGET_DEFAULT=1
Target: arm-linux-gnueabi
Configured with: ... --with-arch=armv5t --host=x86_64-linux-gnu --target=arm-linux-gnueabi ...
gcc version xxx

Solution 2:[2]

maybe the linked library is error. you can assign the link flag with -L int cxx or c flags.

in the new version gcc, gcc -v , not show --with-arch.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 tpcz
Solution 2 user2715069