<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Apr 2, 2019, at 17:37, Louis Dionne via libcxx-dev <<a href="mailto:libcxx-dev@lists.llvm.org" class="">libcxx-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br class="Apple-interchange-newline"><br class=""><blockquote type="cite" class=""><div class="">On Apr 2, 2019, at 17:21, Louis Dionne via libcxx-dev <<a href="mailto:libcxx-dev@lists.llvm.org" class="">libcxx-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><br class="Apple-interchange-newline"><br class=""><blockquote type="cite" class=""><div class="">On Apr 1, 2019, at 19:01, Eric Fiselier via libcxx-dev <<a href="mailto:libcxx-dev@lists.llvm.org" class="">libcxx-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><br class="Apple-interchange-newline"><br class=""><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Apr 1, 2019 at 9:46 AM TheAspiringHacker via libcxx-dev <<a href="mailto:libcxx-dev@lists.llvm.org" class="">libcxx-dev@lists.llvm.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div class="">Hello,<br class=""></div><div class=""><br class=""></div><div class="">I have downloaded LLVM and Clang 8 from the APT repository (deb<span class="Apple-converted-space"> </span><a href="http://apt.llvm.org/xenial/" target="_blank" class="">http://apt.llvm.org/xenial/</a><span class="Apple-converted-space"> </span>llvm-toolchain-xenial-8 main). When I compile and link<br class=""></div><div class=""><br class=""></div><div class="">#include <filesystem><br class=""></div><div class=""><br class=""></div><div class="">namespace fs = std::filesystem;<br class=""></div><div class=""><br class=""></div><div class="">int main()<br class=""></div><div class="">{<br class=""></div><div class=""> <span class="Apple-converted-space"> </span>fs::path wd = fs::current_path();<br class=""></div><div class=""> <span class="Apple-converted-space"> </span>return 0;<br class=""></div><div class="">}<br class=""></div><div class=""><br class=""></div><div class="">with clang-8 -std=c++17 -stdlib=libc++ -lc++ -lc++abi -lc++fs test.cpp -v</div><div class=""><br class=""></div><div class="">I get the output:<br class=""></div><div class=""><br class=""></div><div class="">clang version 8.0.0-svn356034-1~exp1~20190313094121.53 (branches/release_80)<br class=""></div><div class="">Target: x86_64-pc-linux-gnu<br class=""></div><div class="">Thread model: posix<br class=""></div><div class="">InstalledDir: /usr/bin<br class=""></div><div class="">Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/5<br class=""></div><div class="">Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/5.5.0<br class=""></div><div class="">Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6<br class=""></div><div class="">Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/6.5.0<br class=""></div><div class="">Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7<br class=""></div><div class="">Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/7.4.0<br class=""></div><div class="">Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/8<br class=""></div><div class="">Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5<br class=""></div><div class="">Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.5.0<br class=""></div><div class="">Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6<br class=""></div><div class="">Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.5.0<br class=""></div><div class="">Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7<br class=""></div><div class="">Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/7.4.0<br class=""></div><div class="">Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8<br class=""></div><div class="">Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/5.5.0<br class=""></div><div class="">Candidate multilib: .;@m64<br class=""></div><div class="">Selected multilib: .;@m64<br class=""></div><div class="">"/usr/lib/llvm-8/bin/clang" -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model static -mthread-model posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -v -resource-dir /usr/lib/llvm-8/lib/clang/8.0.0 -internal-isystem /usr/lib/llvm-8/bin/../include/c++/v1 -internal-isystem /usr/include/clang/8.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-8/lib/clang/8.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=c++17 -fdeprecated-macro -fdebug-compilation-dir /home/<username> -ferror-limit 19 -fmessage-length 0 -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -o /tmp/test-b088e9.o -x c++ test.cpp -faddrsig<br class=""></div><div class="">clang -cc1 version 8.0.0 based upon LLVM 8.0.0 default target x86_64-pc-linux-gnu<br class=""></div><div class="">ignoring nonexistent directory "/include"<br class=""></div><div class="">ignoring duplicate directory "/usr/include/clang/8.0.0/include"<br class=""></div><div class="">#include "..." search starts here:<br class=""></div><div class="">#include <...> search starts here:<br class=""></div><div class="">/usr/lib/llvm-8/bin/../include/c++/v1<br class=""></div><div class="">/usr/include/clang/8.0.0/include<br class=""></div><div class="">/usr/local/include<br class=""></div><div class="">/usr/include/x86_64-linux-gnu<br class=""></div><div class="">/usr/include<br class=""></div><div class="">End of search list.<br class=""></div><div class="">"/usr/bin/ld" --hash-style=both --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /usr/bin/../lib/gcc/x86_64-linux-gnu/5.5.0/../../../x86_64-linux-gnu/crt1.o /usr/bin/../lib/gcc/x86_64-linux-gnu/5.5.0/../../../x86_64-linux-gnu/crti.o /usr/bin/../lib/gcc/x86_64-linux-gnu/5.5.0/crtbegin.o -L/usr/bin/../lib/gcc/x86_64-linux-gnu/5.5.0 -L/usr/bin/../lib/gcc/x86_64-linux-gnu/5.5.0/../../../x86_64-linux-gnu -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/bin/../lib/gcc/x86_64-linux-gnu/5.5.0/../../.. -L/usr/lib/llvm-8/bin/../lib -L/lib -L/usr/lib -lc++ -lc++abi -lc++fs /tmp/test-b088e9.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/bin/../lib/gcc/x86_64-linux-gnu/5.5.0/crtend.o /usr/bin/../lib/gcc/x86_64-linux-gnu/5.5.0/../../../x86_64-linux-gnu/crtn.o<br class=""></div><div class="">/tmp/test-b088e9.o: In function `std::__1::__fs::filesystem::current_path()':<br class=""></div><div class="">test.cpp:(.text._ZNSt3__14__fs10filesystem12current_pathEv[_ZNSt3__14__fs10filesystem12current_pathEv]+0x14): undefined reference to `std::__1::__fs::filesystem::__current_path(std::__1::error_code*)'<br class=""></div><div class="">clang: error: linker command failed with exit code 1 (use -v to see invocation)<br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">I ran:<br class=""></div><div class=""><br class=""></div><div class="">nm -C /usr/lib/llvm-8/lib/libc++fs.a | fgrep 'std::__1::__fs::filesystem::__current_path'<br class=""></div><div class=""><br class=""></div><div class="">and got:<br class=""></div><div class=""><br class=""></div><div class="">0000000000002540 T std::__1::__fs::filesystem::__current_path(std::__1::error_code*)<br class=""></div><div class="">0000000000002880 T std::__1::__fs::filesystem::__current_path(std::__1::__fs::filesystem::path const&, std::__1::error_code*)<br class=""></div><div class=""><br class=""></div><div class="">It seems that the `current_path` functions, as defined in the libc++fs.a file that I installed, do not match the overloads as documented at<span class="Apple-converted-space"> </span><a href="https://en.cppreference.com/w/cpp/filesystem/current_path" target="_blank" class="">https://en.cppreference.com/w/cpp/filesystem/current_path</a><span class="Apple-converted-space"> </span>or specified in the filesystem header file of libc++. According to<span class="Apple-converted-space"> </span><a href="http://libcxx.llvm.org/ts1z_status.html" target="_blank" class="">http://libcxx.llvm.org/ts1z_status.html</a>, as of June 17, 2016, the filesystem library is complete. For comparison, the APT repository was last updated on March 27, 2019.<br class=""></div><div class=""><br class=""></div><div class="">I do not know if perhaps I made a mistake in linking the code or installing the library.<span class="Apple-converted-space"> </span><a href="https://libcxx.llvm.org/" target="_blank" class="">https://libcxx.llvm.org/</a><span class="Apple-converted-space"> </span>directed me to ask here if I'm not sure whether I found a bug.<br class=""></div><div class=""><br class=""></div><div class="">Is this an issue with the files I downloaded from the APT repository, or is it my own mistake?<br class=""></div></blockquote><div class=""><br class=""></div><div class="">Your invocation of Clang puts -lc++fs before the source file that depends on it.</div><div class="">You need to put the source file before the libraries. Ex:</div><div class=""><br class=""></div><div class=""> clang-8 -std=c++17 -stdlib=libc++ test.cpp -lc++fs -v<br class=""></div></div></div></div></blockquote></div><div class="" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><br class=""></div><span class="" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;">Isn't that something that Clang should handle?</span></div></blockquote><br class=""></div><div style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">To clarify, what I meant is that from a very naive point of view, the order in which you provide `-l`'s on the command line shouldn't matter -- it should work as long as you provide the right set of `-l`'s. I'm puzzled every time a tool (e.g. `ld`) behaves differently based on the order of command line arguments.</div><div style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br class=""></div><div style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">Maybe there's a good reason for this, though. Maybe the cfe-dev folks can explain?</div></div></blockquote><div><br class=""></div><div>Getting the right order requires evaluating the dependencies. Clang has to rely on the underlying linker to do this, so the logic can't be in Clang itself.</div><div><br class=""></div><div>On Darwin, ld64 does a pre-scan to build a hash of symbols so that it can handle out-of-order libraries. Probably some other linkers do the same, but many just don't support that. If you have cycles, you need to either list libraries twice or otherwise use command-line arguments to get the linker to rescan the list.</div></div><br class=""></body></html>