交叉编译:链接时对 std::__atomic_futex_unsigned_base::_M_futex_notify_all(unsigned int*) 的未定义引用

Posted

技术标签:

【中文标题】交叉编译:链接时对 std::__atomic_futex_unsigned_base::_M_futex_notify_all(unsigned int*) 的未定义引用【英文标题】:crosscompile: undefined reference to std::__atomic_futex_unsigned_base::_M_futex_notify_all(unsigned int*) when linking 【发布时间】:2017-10-29 10:21:44 【问题描述】:

我想在 arm 平台上交叉编译 tiny-dnn(一个 c++14 项目,https://github.com/tiny-dnn/tiny-dnn)。 所以我安装了g++-arm-Linux-gnueabi和gcc-arm-Linux-gnueabi,版本是GCC5.4。 然后我修改了 CMakeList 以添加一些标志。

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()

然后我添加了一些标志:

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

最后,所有的标志(一些标志显示两次)是:

-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

最后我得到了这些错误:

[ 6%] 构建 CXX 对象 示例/CMakeFiles/example_mnist_train.dir/mnist/train.cpp.o [ 12%] 链接 CXX 可执行文件 example_mnist_train CMakeFiles/example_mnist_train.dir/mnist/train.cpp.o:在函数中 std::__future_base::_State_baseV2::_M_set_result(std::function ()>, bool) [克隆 .constprop.5599]': train.cpp:(.text+0x584): 未定义参考 tostd::__atomic_futex_unsigned_base::_M_futex_notify_all(unsigned int*)' CMakeFiles/example_mnist_train.dir/mnist/train.cpp.o:在 功能 std::__future_base::_State_baseV2::_M_set_result(std::function ()>, bool) [克隆 .constprop.5600]': train.cpp:(.text+0x67c): 未定义参考 tostd::__atomic_futex_unsigned_base::_M_futex_notify_all(unsigned int*)' CMakeFiles/example_mnist_train.dir/mnist/train.cpp.o:在 函数`std::__future_base::_Result::~_Result()':

...等

它似乎不能引用标准库。我错过了什么吗?

顺便说一句,我可以在 Nvidia TX1 和 Raspbian Pi 上编译该项目,所以该项目应该与 ARM 兼容。

【问题讨论】:

当你输入/path/to/your/gcc/lib/libstdc++.a | grep _M_futex_notify_all时你看到了什么? 我输入了sudo cat ./libstdc++.a | grep _M_futex_notify_all,没有找到匹配项。在普通 gcc 上尝试了代码,得到了二进制匹配。所以我应该尝试其他一些跨工具链还是自己编译一个。 抱歉打错了,我的错。你需要nm -C /path/to/your/gcc/lib/libstdc++.a | grep _M_futex_notify_all(以及为什么需要sudo?!) 尝试了新代码,没有返回任何内容。在普通的 GCC 上尝试了代码,返回:00000000000000 T std::__atomic_futex_unsigned_base::_M_futex_notify_all(unsigned int*) U std::__atomic_futex_unsigned_base::_M_futex_notify_all(unsigned int*) 你能在 arm 库中找到任何其他函数吗,例如nm ... | grep basic_string? 【参考方案1】:

检查您的 gcc 是如何使用 gcc -v 编译的。如果您的项目使用的 -march 标志所需的架构与用于 gcc 编译的 --with-arch 值不匹配,则可能会导致类似于您所指的问题。

在这种情况下,您可能需要为您的平台获取另一个工具链和运行时。

gcc -v 将给出类似于下面的输出,检查配置部分中的--with-arch 标志:

$ 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

【讨论】:

以上是关于交叉编译:链接时对 std::__atomic_futex_unsigned_base::_M_futex_notify_all(unsigned int*) 的未定义引用的主要内容,如果未能解决你的问题,请参考以下文章

JNI_3

Raspberry pi opencv 链接问题的交叉编译

链接器错误:未定义的函数引用

ubuntu 交叉编译 armv7_32 ffmpeg x264(已完成)

c++编译错误“需要'_InputIterator std::__find_if(_InputIterator, _InputIterator, _Predicate, std::input_iter

g++ 编译错误:std::ctype<char>、std::__detail、std::allocator<Taquart