0

Whenever I run this code I get segmentation fault(core dumped). It compiles without error or warnings but I still get the segfault.

I'm running on Ubuntu 19.04 on amd ryzen 2400g

I've compiled it on g++-8 and clang-8, and in both I get the seg fault. After debugging it to catch the segfault, I found it in fs::path's destructor which is =default

#include <iostream>
#include <filesystem>
namespace fs = std::filesystem; 

int main()
{
    fs::path p = fs::current_path();

    std::cout << p.c_str() << std::endl;
}

This is only supposed to print out the directory that the program is run from. I tried this to run recusrsive_directory_iterator to make a directory viewer but I ended up with the error.

Kenny Castro
  • 121
  • 11
  • 3
    *It compiles without error...* -- This has nothing to do with what will happen at runtime. All this means is that there are no syntax errors, and the linker has resolved all of the functions that you're calling -- nothing more, nothing less. – PaulMcKenzie Jul 05 '19 at 15:51
  • 2
    What was the command-line you used to compile the code? [Cannot duplicate the error here](https://coliru.stacked-crooked.com/a/4cd6f098bfa12f3a) – PaulMcKenzie Jul 05 '19 at 15:59
  • 1
    Are you linking `-stdc++fs` in your link line?, IIRC you need to link that - at least that was required back when it was in the "experimental" phase (pre c++17) – code_fodder Jul 05 '19 at 16:17
  • I wasn't linking with `-stdc++fs`. When I added that to the compile flags it worked. Looks like that was all I needed – Kenny Castro Jul 07 '19 at 14:13

0 Answers0