我试图推出新的filesystemSTL库,但由于某种原因我遇到了错误.该Clang++7网站表明它应该支持新的filesystem图书馆 - 事实上我clang已经超前了g++.
我使用了另一个Stack Exchange帖子中的一些代码,因此根据upvotes的数量它应该是有效的.这可能会转到指定的目录并打印该目录中的所有文件.这是代码.
#include <iostream>
#include <string>
#include <experimental/filesystem>
namespace fs = std::experimental::filesystem;
int main(int argc, char *argv[])
{
std::string path = "/home/.../Downloads";
for (const auto & entry : fs::directory_iterator(path))
{
std::cout << entry.path() << std::endl;
}
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误消息是:
CMakeFiles/filesystem_app.dir/main.cpp.o: In function `main':
/media/.../clangcpp/filesystem_app/main.cpp:13: undefined reference to `std::experimental::filesystem::v1::__cxx11::directory_iterator::operator*() const'
/media/.../clangcpp/filesystem_app/main.cpp:13: undefined reference to `std::experimental::filesystem::v1::__cxx11::directory_iterator::operator++()'
CMakeFiles/filesystem_app.dir/main.cpp.o: In function `path<std::__cxx11::basic_string<char>, std::experimental::filesystem::v1::__cxx11::path>':
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.5.0/../../../../include/c++/5.5.0/experimental/fs_path.h:198: undefined reference to `std::experimental::filesystem::v1::__cxx11::path::_M_split_cmpts()'
CMakeFiles/filesystem_app.dir/main.cpp.o: In function `directory_iterator':
/usr/bin/../lib/gcc/x86_64-linux-gnu/5.5.0/../../../../include/c++/5.5.0/experimental/fs_dir.h:188: undefined reference to `std::experimental::filesystem::v1::__cxx11::directory_iterator::directory_iterator(std::experimental::filesystem::v1::__cxx11::path const&, std::experimental::filesystem::v1::directory_options, std::error_code*)'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)
我确保包含experimental/filesystem标题而不是filesystem删除Clion中任何红色曲线的标题.我试图从CLion以及命令行编译.我使用的编译字符串是:
clang++-7 -Wall -std=c++17 main.cpp -o app
Run Code Online (Sandbox Code Playgroud)
有没有人知道这里有什么问题?在编译错误消息中,我看到了引用std::experimental::filesystem::v1::__cxx11::..,我想知道为什么这不说cxx17,但我不确定这是否是问题的原因.我c++17在上面的编译字符串中明确指出.
filesystem 仍然是实验性的,需要一个额外的库.
如果您使用的是libstdc ++,请链接-lstdc++fs(或target_link_libraries(${PROJECT_NAME} stdc++fs)).
对于libc ++,请使用-lc++fs(类似于CMake命令).
| 归档时间: |
|
| 查看次数: |
586 次 |
| 最近记录: |