experimental :: filesystem链接器错误 [英] experimental::filesystem linker error

查看:258
本文介绍了experimental :: filesystem链接器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



如果我尝试这个小例子:



  #include< iostream> 
#include< experimental / filesystem>
命名空间fs = std :: experimental :: filesystem;
int main()
{
fs :: path p1 =/ home / pete / checkit;

std :: cout<< p1 =<< p1<<的std :: ENDL;
}

我得到了:

 
/ opt / linux-gnu_6-20151011 / bin / g ++ --std = c ++ 1z main.cpp -O2 -g -o go
/tmp/ccaGzqFO.o:在函数\`std :: experimental :: filesystem :: v1 :: __ cxx11 :: path :: path(char const(&)[36])'中:
/ opt / linux-gnu_6-20151011 / include /c++/6.0.0/experimental/bits/fs_path.h:167:未定义对`std :: experimental :: filesystem :: v1 :: __ cxx11 :: path :: _ M_split_cmpts()'的引用
collect2:error :ld返回1退出状态

gcc版本是快照linux-gnu_6-20151011

任何提示如何链接到新的c ++ 1z功能?

解决方案

Filesystem TS与无关C ++ 1z支持,它是一个完全独立的规范,不是C ++ 1z工作草案的一部分。 GCC的实现(在GCC 5.3和更高版本中)甚至可以用C ++ 11模式。

fs 来使用它。



(相关库, libstdc ++ fs.a 是一个静态库,所以任何静态库都应该在之后任何依赖于它的对象在链接器命令中。)



2017年11月更新:以及Filesystem TS,GCC主干现在 也有一个C ++ 17文件系统库的实现,在 < code>>文件系统> 和命名空间 std :: filesystem (注意这些名称中没有experimental)。 std = gnu ++ 17 或 -std = c ++ 17 。 GCC的C ++ 17支持尚不完整或稳定,直到它被认为可以在黄金时间使用时,您还需要链接到C ++的 -lstdc ++ fs +17文件系统功能。


I try to use the new c++1z features actually on the head of development within gcc 6.0.

If I try this little example:

#include <iostream>
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
int main()
{
    fs::path p1 = "/home/pete/checkit";

    std::cout << "p1 = " << p1 << std::endl;
}

I got:

/opt/linux-gnu_6-20151011/bin/g++ --std=c++1z main.cpp -O2 -g -o go
/tmp/ccaGzqFO.o: In function \`std::experimental::filesystem::v1::__cxx11::path::path(char const (&) [36])':
/opt/linux-gnu_6-20151011/include/c++/6.0.0/experimental/bits/fs_path.h:167: undefined reference to `std::experimental::filesystem::v1::__cxx11::path::_M_split_cmpts()'
collect2: error: ld returned 1 exit status

gcc version is the snapshot linux-gnu_6-20151011

Any hints how to link for the new c++1z features?

解决方案

The Filesystem TS is nothing to do with C++1z support, it is a completely separate specification not part of the C++1z working draft. GCC's implementation (in GCC 5.3 and later) is even available in C++11 mode.

You just need to link with -lstdc++fs to use it.

(The relevant library, libstdc++fs.a, is a static library, so as with any static library it should come after any objects that depend on it in the linker command.)

Update Nov 2017: as well as the Filesystem TS, GCC trunk now also has an implementation of the C++17 Filesystem library, defined in <filesystem> and in namespace std::filesystem (N.B. no "experimental" in those names) when using -std=gnu++17 or -std=c++17. GCC's C++17 support is not complete or stable yet, and until it's considered ready for prime time use you also need to link to -lstdc++fs for the C++17 Filesystem features.

这篇关于experimental :: filesystem链接器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆