Link errors using members in C++17

前端 未结 3 1938
小鲜肉
小鲜肉 2020-12-04 01:38

I\'m using gcc 7.2 on Ubuntu 16.04, and I need to use the new filesystem library from C++17. Even though there is indeed a library called experimental/filesystem, I can\'t u

3条回答
  •  青春惊慌失措
    2020-12-04 01:56

    You can also sudo apt install g++-8 and use #include as cppreference described instead of #include in older g++ and libstdc++ version.

    If I install gcc 8 in Ubuntu, will I have 2 different libstdc++ library or merely the original one get updated?

    you'll probably have two even though the newer one should work as a drop-in replacement for the old one.

    I notice that a libstdc++-8-dev is installed along with g++-8.

    This works for me:

    g++-8 -g -Wall -std=c++17 test.cpp -lstdc++fs

    It seems that even with g++-8, the filesystem library is not automatically linked, you still need to provide -lstdc++fs, and -std=c++17 is also needed in language level.

提交回复
热议问题