1
votes

I try c++1z feature to use std::experimental::filesystem

After adding -lstdc++fs flag with g++, I can see that I am able to link std::experimental::filesystem::v1::__cxx11::path::_M_split_cmpts() with my program.

i.e I am not getting this error anymore

sdc.cpp:(.text+0x7e5): undefined reference to `std::experimental::filesystem::v1::__cxx11::path::_M_split_cmpts()'

However, even after linking, I get the following error.

g++ -std=c++1z timer.cpp -lstdc++fs -O2 -I include -L lib -lOpenTimer -lpthread -o timer.out lib/libOpenTimer.a(spef.cpp.o): In function spef::Spef::read(std::experimental::filesystem::v1::__cxx11::path const&)': spef.cpp:(.text._ZN4spef4Spef4readERKNSt12experimental10filesystem2v17__cxx114pathE[_ZN4spef4Spef4readERKNSt12experimental10filesystem2v17__cxx114pathE]+0x2e): undefined reference tostd::experimental::filesystem::v1::status(std::experimental::filesystem::v1::__cxx11::path const&)' lib/libOpenTimer.a(sdc.cpp.o): In function ot::sdc::home[abi:cxx11]()': sdc.cpp:(.text+0x414): undefined reference tostd::experimental::filesystem::v1::status(std::experimental::filesystem::v1::__cxx11::path const&)' sdc.cpp:(.text+0x7ab): undefined reference to std::experimental::filesystem::v1::status(std::experimental::filesystem::v1::__cxx11::path const&)' lib/libOpenTimer.a(sdc.cpp.o): In functionot::sdc::SDC::read(std::experimental::filesystem::v1::__cxx11::path const&)': sdc.cpp:(.text+0x2fa1): undefined reference to std::experimental::filesystem::v1::status(std::experimental::filesystem::v1::__cxx11::path const&)' sdc.cpp:(.text+0x3084): undefined reference tostd::experimental::filesystem::v1::status(std::experimental::filesystem::v1::__cxx11::path const&)' sdc.cpp:(.text+0x30db): undefined reference to std::experimental::filesystem::v1::current_path[abi:cxx11]()' sdc.cpp:(.text+0x30f7): undefined reference tostd::experimental::filesystem::v1::absolute(std::experimental::filesystem::v1::__cxx11::path const&, std::experimental::filesystem::v1::__cxx11::path const&)' sdc.cpp:(.text+0x3788): undefined reference to std::experimental::filesystem::v1::remove(std::experimental::filesystem::v1::__cxx11::path const&)' lib/libOpenTimer.a(os.cpp.o): In functionot::user_homeabi:cxx11': os.cpp:(.text+0x30d): undefined reference to `std::experimental::filesystem::v1::current_pathabi:cxx11' collect2: error: ld returned 1 exit status

Any help to resolve this would be much appreciated.

1

1 Answers

1
votes

It was me who posted the question. It seems like I was able to resolve it myself.

I added the -lstdc++fs at the end instead of middle and it started working.

Here's the updated command

g++ -std=c++1z timerapp.cpp -O2 -I include -L lib -lOpenTimer -lpthread -o timer.out -lstdc++fs

compared to the previous command

g++ -std=c++1z timerapp.cpp -lstdc++fs -O2 -I include -L lib -lOpenTimer -lpthread -o timer.out

Don't know why some linking flags are expected to be added in the end though.