代码之家  ›  专栏  ›  技术社区  ›  Bill Forster

在C++编译器模式下,是否可以将标准的C++17<文件系统>功能与Zig一起使用?

  •  1
  • Bill Forster  · 技术社区  · 4 年前

    我刚开始学习Zig。我在Windows 10上使用Zig 0.9.0。吸引我的一个特性是使用Zig作为C或C++编译器或交叉编译器。我已经成功地将Zig用于一些玩具程序,但当我尝试使用C++17的标准库文件系统设施时,我的运气就没了。这里是一个最小的例子;

    #include <stdio.h>
    #include <filesystem>
    
    int main( int argc, char *argv[] )
    {
        std::string s("src/zigtest.cpp");
        std::filesystem::path p(s); 
        bool exists = std::filesystem::exists(p);
        printf( "File %s %s\n", s.c_str(), exists ? "exists" : "doesn't exist" );
        return 0;
    }
    

    如果我尝试使用以下命令构建此;

    zig c++ -std=c++17 src\zigtest.cpp
    

    我得到以下链接错误;

    lld-link: error: undefined symbol: std::__1::__fs::filesystem::__status(std::__1::__fs::filesystem::path const&, std::__1::error_code*)
    >>> referenced by ...
    

    顺便说一句,很长一段时间我都没有走到这一步,结果我需要应用-std=c++17标志,直到那时我才出现编译错误,而不是链接错误;

    src\zigtest.cpp:7:10: error: no member named 'filesystem' in namespace 'std'
    

    最后,我要注意的是(在谷歌上搜索了一下)我尝试传递-lsdc++fs标志,但也没有成功。在这种情况下,我明白;

    error(link): DLL import library for -lstdc++fs not found
    error: DllImportLibraryNotFound
    
    0 回复  |  直到 4 年前
        1
  •  3
  •   Marshall Clow    4 年前

    一些评论:你看到的事实 std::__1::__fs::filesystem 意味着您正在使用libc++。

    正在尝试链接到 libstdc++fs 这是一个gcc的东西,即使你的系统上有它,也不会工作。

    您正在使用哪个版本的libc++? libc++的文档如下:

    他们谈论使用 <filesystem> 以及你必须链接到什么(如果有的话)。

        2
  •  1
  •   kristoff    4 年前

    应该在这个PR中解决。Jakub和Spex在我将这个问题联系起来后立即着手解决:^)

    https://github.com/ziglang/zig/pull/10563