我需要使用(实验性的)C++17
文件系统库编写程序,但我的Mac(macOS 10.12.03)上的clang
似乎没有包含文件系统头文件。
由于我需要使用C++17
,因此我不能使用Boost
库等替代品。
当我尝试编译一个只包括文件系统和iostream
的示例程序(并写入cout
)时
#include <filesystem>
#include <iostream>
using namespace std;
int main(){
cout << "test" << endl;
}
我收到了以下错误信息:
>clang test.cpp -std=c++1z
test.cpp:2:10: fatal error: 'filesystem' file not found
#include <filesystem>
^
1 error generated.
当我尝试使用通过homebrew安装的GCC 6.3进行相同操作时,我得到:
>gcc-6 test.cpp -std=c++17
test.cpp:2:22: fatal error: filesystem: No such file or directory
#include <filesystem>
^
compilation terminated.
我也尝试使用experimental/filesystem,它可以使用gcc编译,但似乎会尝试为iOS编译,导致另一个与iostream相关的错误。
Undefined symbols for architecture x86_64:
"std::ios_base::Init::Init()", referenced from:
__static_initialization_and_destruction_0(int, int) in ccd5QiVt.o
"std::ios_base::Init::~Init()", referenced from:
__static_initialization_and_destruction_0(int, int) in ccd5QiVt.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
我的clang版本是:
>clang --version
Apple LLVM version 8.0.0 (clang-800.0.42.1)
Target: x86_64-apple-darwin16.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
我非常感谢任何有帮助的意见,因为到目前为止我还没有找到解决我的问题的任何东西(尽管我可能搜索了错误的术语)。
如果需要更多信息,我很乐意提供,但我希望已经包含了所有必要的内容。
<filesystem>
。 - EricWFstd::experimental
),那么它就不是C++17文件系统库。 - Davis Herring