crosstool-ng - 使用 C++14 支持为 Raspberry Pi 构建 g++

如何解决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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?