大佬教程收集整理的这篇文章主要介绍了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 (将#修改为@)
以上是大佬教程为你收集整理的crosstool-ng - 使用 C++14 支持为 Raspberry Pi 构建 g++全部内容,希望文章能够帮你解决crosstool-ng - 使用 C++14 支持为 Raspberry Pi 构建 g++所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。