相关文章推荐

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement . We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I get an error during make:

#/usr/bin/ld: tiv.o: in function std::filesystem::__cxx11::path::path<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::filesystem::__cxx11::path>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::filesystem::__cxx11::path::format)': tiv.cpp:(.text._ZNSt10filesystem7__cxx114pathC2INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES1_EERKT_NS1_6formatE[_ZNSt10filesystem7__cxx114pathC5INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES1_EERKT_NS1_6formatE]+0x40): undefined reference to std::filesystem::__cxx11::path::_M_split_cmpts()'
/usr/bin/ld: tiv.o: in function main': tiv.cpp:(.text.startup+0x180e): undefined reference to std::filesystem::status(std::filesystem::__cxx11::path const&)'
/usr/bin/ld: tiv.cpp:(.text.startup+0x195a): undefined reference to std::filesystem::__cxx11::directory_iterator::directory_iterator(std::filesystem::__cxx11::path const&, std::filesystem::directory_options, std::error_code*)' /usr/bin/ld: tiv.cpp:(.text.startup+0x19d7): undefined reference to std::filesystem::__cxx11::directory_iterator::operator*() const'
/usr/bin/ld: tiv.cpp:(.text.startup+0x19e2): undefined reference to std::filesystem::status(std::filesystem::__cxx11::path const&)' /usr/bin/ld: tiv.cpp:(.text.startup+0x19f2): undefined reference to std::filesystem::__cxx11::directory_iterator::operator++()'
collect2: error: ld returned 1 exit status
make: *** [Makefile:23: tiv] Fehler 1

I also got this issue, on Chromebook (lenovo duet) in linux container:

$ cat /etc/debian_version 
$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/aarch64-linux-gnu/8/lto-wrapper
Target: aarch64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 8.3.0-6' --with-bugurl=file:///usr/share/doc/gcc-8/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-8 --program-prefix=aarch64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-bootstrap --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-libquadmath --disable-libquadmath-support --enable-plugin --enable-default-pie --with-system-zlib --disable-libphobos --enable-multiarch --enable-fix-cortex-a53-843419 --disable-werror --enable-checking=release --build=aarch64-linux-gnu --host=aarch64-linux-gnu --target=aarch64-linux-gnu
Thread model: posix
gcc version 8.3.0 (Debian 8.3.0-6)
$ make
g++ -O2 -fpermissive -std=c++17 -Wall -fexceptions   -c -o tiv.o tiv.cpp
g++ -pthread tiv.o -o tiv  
/usr/bin/ld: tiv.o: in function `std::filesystem::__cxx11::path::path<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::filesystem::__cxx11::path>(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::filesystem::__cxx11::path::format)':
tiv.cpp:(.text._ZNSt10filesystem7__cxx114pathC2INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES1_EERKT_NS1_6formatE[_ZNSt10filesystem7__cxx114pathC5INSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEES1_EERKT_NS1_6formatE]+0x48): undefined reference to `std::filesystem::__cxx11::path::_M_split_cmpts()'
/usr/bin/ld: tiv.o: in function `main':
tiv.cpp:(.text.startup+0x11dc): undefined reference to `std::filesystem::status(std::filesystem::__cxx11::path const&)'
/usr/bin/ld: tiv.cpp:(.text.startup+0x12d4): undefined reference to `std::filesystem::__cxx11::directory_iterator::directory_iterator(std::filesystem::__cxx11::path const&, std::filesystem::directory_options, std::error_code*)'
/usr/bin/ld: tiv.cpp:(.text.startup+0x1324): undefined reference to `std::filesystem::__cxx11::directory_iterator::operator*() const'
/usr/bin/ld: tiv.cpp:(.text.startup+0x132c): undefined reference to `std::filesystem::status(std::filesystem::__cxx11::path const&)'
/usr/bin/ld: tiv.cpp:(.text.startup+0x1340): undefined reference to `std::filesystem::__cxx11::directory_iterator::operator++()'
collect2: error: ld returned 1 exit status
make: *** [Makefile:23: tiv] Error 1

It works using the extra flag mention above:

# Working:
$ make LDLIBS=-lstdc++fs

Aaron, can we just always add this flag? Or will it break Mac or anything else you are aware of?

Probably. For now just go ahead and add the flag.

If I add the flag, it doesn't seem to compile on MacOS any longer.

Manjaro Linux seems to work fine with or without the flag.

So I have just added the workaround to the README for now.

Would be nice to figure out when it's needed (in a way we can integrate into the Makefile)

I had a similar error on Ubuntu 18.04. Turns out recent enough version of gcc is needed

This is what fixed error for me:

sudo apt install g++-8
export CXX="g++-8" CC="gcc-8"
make LDLIBS=-lstdc++fs

Most solutions are seemed to be based on 'make' but not 'bazel build'.
I think install with g++-8 should be the first step, while once still met with building error of "invalid reference to std::filesystem", you can try to do this:
revise 'build --linkopt=-ldl' to 'build --linkopt=-lstdc++fs' in .bazelrc
This finally works well for me

 
推荐文章