Experimental::Filesystem Linker Error

experimental::filesystem linker error

The Filesystem TS is nothing to do with C++1z support, it is a completely separate specification not part of the C++1z working draft. GCC's implementation (in GCC 5.3 and later) is even available in C++11 mode.

You just need to link with -lstdc++fs to use it.

(The relevant library, libstdc++fs.a, is a static library, so as with any static library it should come after any objects that depend on it in the linker command.)

Update Nov 2017: as well as the Filesystem TS, GCC 8.x also has an implementation of the C++17 Filesystem library, defined in <filesystem> and in namespace std::filesystem (N.B. no "experimental" in those names) when using -std=gnu++17 or -std=c++17. GCC's C++17 support is not complete or stable yet, and until it's considered ready for prime time use you also need to link to -lstdc++fs for the C++17 Filesystem features.

Update Jan 2019: starting with GCC 9, the C++17 std::filesystem components can be used without -lstdc++fs (but you still need that library for std::experimental::filesystem).

Undefined reference error with new filesystem library and clang++7

filesystem is still experimental and requires an extra library.

If you are using libstdc++, link with -lstdc++fs (or target_link_libraries(${PROJECT_NAME} stdc++fs)).

For libc++, use -lc++fs (similar for the CMake command).

experimental::filesystem linker error while using GCC6 after using -lstdc++fs option

As written in the GCC documentation:

-llibrary

-l library

...

It makes a difference where in the command you write this option; the
linker searches and processes libraries and object files in the order
they are specified. Thus, ‘foo.o -lz bar.o’ searches library ‘z’ after
file foo.o but before bar.o. If bar.o refers to functions in ‘z’,
those functions may not be loaded.

Thus you have to put -lstdc++fs after test.cpp on the command line.

Link errors using filesystem members in C++17

Add the flag -lstdc++fs:

$ g++-7 test.cpp -std=c++17 -lstdc++fs

gcc 7.2 supports C++17 experimental filesystem namespace only. I do not know, maybe gcc 7.3 supports std filesystem namespace already.

Linker error using experimental/filesystem and calling a function

It looks like there's a windows library that you need to link with that is not being included automatically. The symbols that the linker isn't finding, CreateTransaction and CommitTransaction, are in KtmW32.dll, so you'll need to include a reference to KtmW32.lib.

undefined reference when using experimental/filesystem

The following command line work great for me (GCC 7.2.0 on Ubuntu 17.10):

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

Note that when you omit the -lstdc++fs or put it before test.cpp in the command line, the linking will fail with the undefined reference error you've observed.

How to avoid std::filesystem linker errors with Qt?

<filesystem> is a separate library for GCC 8 (see this question). Your issue, as you suspected, is in the order of the flags. Poking about a bit in the docs hints that QMAKE_LFLAGS is more for linker flags than library loads, which is why it gets passed early (e.g. -O3).

Using LIBS += -lstdc++fs should work instead.

Credit to this reddit response for this solution.



Related Topics



Leave a reply



Submit