如何解决crosstool-ng - 使用 C++14 支持为 Raspberry Pi 构建 g++
我决定使用 crosstool-ng
为我的 Pi 2 创建一个交叉编译工具链。幸运的是,有一个我依赖的示例配置。经过几个问题,我设法构建了我想要的。或者我是这么想的...
我有一个面向 C++14 的项目,其中包含实验性的 filesystem
库,该库通过 <experimental/filesystem>
包含。代码在我的 32 位 Ubuntu 16.04 LTS 上完美编译。所需的 -lstdc++fs
当然存在,以便链接器处理与文件系统相关的内容。 gcc
版本是 10.2。以下问题可以通过它重现,但我会尝试将版本降低到 9.x 以查看是否可以绕过它。
运行时
./armv7-rpi2-linux-gnueabihf/bin/armv7-rpi2-linux-gnueabihf-g++ -std=c++14 -lstdc++fs - lpthread main.cpp -o test
我收到以下消息:
/home/USER/x-tools/armv7-rpi2-linux-gnueabihf/lib/gcc/armv7-rpi2-linux-gnueabihf/10.2.0/../../../../armv7-rpi2-linux-gnueabihf/bin/ld: /tmp/ccOLyplp.o: in function `std::experimental::filesystem::v1::__cxx11::path::path<char [2],std::experimental::filesystem::v1::__cxx11::path>(char const (&) [2])':
main.cpp:(.text._ZNSt12experimental10filesystem2v17__cxx114pathC2IA2_cS3_EERKT_[_ZNSt12experimental10filesystem2v17__cxx114pathC5IA2_cS3_EERKT_]+0x5c): undefined reference to `std::experimental::filesystem::v1::__cxx11::path::_M_split_cmpts()'
collect2: error: ld returned 1 exit status
显然这是一个链接器问题。然而,我不明白为什么。为了调查该问题,我通过将目标 C++ 标准版本增加到 C++17
进行了检查。我之前注意到的一件事是,给出以下源代码
#include <iostream>
#include <thread>
#ifndef __has_include
static_assert(false,"__has_include not supported");
#else
#if __has_include(<filesystem>)
#include <filesystem>
namespace fs = std::filesystem;
#elif __has_include(<experimental/filesystem>)
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
#elif __has_include(<boost/filesystem.hpp>)
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
#else
error("Unable to find filesystem library")
#endif
#endif
void tFunc1(int x)
{
for (int i = 0; i < x; ++i)
{
std::cout << ".";
}
std::cout << std::endl;
}
void tFunc2(int x)
{
for (int i = x-1; i >= 0; --i)
{
std::cout << "#";
}
std::cout << std::endl;
}
int main(int argc,char *argv[])
{
std::cout << "Hello crosstool-ng!" << std::endl;
std::thread t1(tFunc1,100);
std::thread t2(tFunc2,100);
t1.join();
t2.join();
fs::path p = "."; // FIXME Not working with -std=c++14 enabled
return 0;
}
选择 C++14
时,我没有收到预期的错误消息。正如我从我在 SO 上的另一篇文章中发现的那样,__has_include
是一个 C++17
。因此,即使我选择了 C++14
,也有 C++17
可用。
切换到 C++17
后,它起作用了。但是我需要坚持使用 C++14。
如果这对我有帮助,我使用的 sysroot
是截至 2021 年 2 月 12 日的最新 RaspBerry 操作系统中的 /usr
副本。Here is my configuration for crosstool-ng
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。