jank-lang / jank

The native Clojure dialect hosted on LLVM
https://jank-lang.org
Mozilla Public License 2.0
1.69k stars 50 forks source link

Issue while linking executable #79

Closed mateodif closed 4 months ago

mateodif commented 4 months ago

Hello :) I'm trying to get jank to compile under Arch Linux and I'm having some issues.

First, I had to change add back some flags (lines 81 and 86 of CMakeLists.txt) in order to use LLVM's C++ stdlib since I was facing issues during compilation with GCC's stdlib.

After this change I'm able to successfully compile jank, but I'm facing an error while linking:

[mateo@navi compiler+runtime]$ ./bin/compile
...
[76/78] Linking CXX executable jank
FAILED: jank
: && /home/mateo/jank/compiler+runtime/build/cling-build/bin/clang++ -O3 -DNDEBUG -Wl,--export-dynamic -rdynamic -s  -Lbuild/cling-build/build-compiler-rt/lib/linux -stdlib=libc++ -lc++abi -v CMakeFiles/jank_exe.dir/src/cpp/main.cpp.o -o jank  -Wl,-rpath,/home/mateo/jank/compiler+runtime/build:  -Wl,--whole-archive  libjank.a  -Wl,--no-whole-archive  -Wl,--whole-archive  libnanobench.a  -Wl,--no-whole-archive  libfolly.a  libjankcling.so  vcpkg_installed/x64-clang-static/lib/libfmt.a  vcpkg_installed/x64-clang-static/lib/libcord.a  vcpkg_installed/x64-clang-static/lib/libgccpp.a  vcpkg_installed/x64-clang-static/lib/libgctba.a  vcpkg_installed/x64-clang-static/lib/libgc.a  -ldl  vcpkg_installed/x64-clang-static/lib/libzippp_static.a  vcpkg_installed/x64-clang-static/lib/libzip.a  vcpkg_installed/x64-clang-static/lib/libbz2.a  vcpkg_installed/x64-clang-static/lib/libcrypto.a  -ldl  vcpkg_installed/x64-clang-static/lib/libz.a  vcpkg_installed/x64-clang-static/lib/libCLI11.a  -lreadline  vcpkg_installed/x64-clang-static/lib/libboost_filesystem.a  vcpkg_installed/x64-clang-static/lib/libboost_system.a  vcpkg_installed/x64-clang-static/lib/libboost_atomic.a && :
clang version 13.0.0 (https://github.com/root-project/llvm-project.git 0a6eae39d07f66c98c4d7160635a6e62693abdbb)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/mateo/jank/compiler+runtime/build/cling-build/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/14.1.1
Found candidate GCC installation: /usr/lib64/gcc/x86_64-pc-linux-gnu/14.1.1
Selected GCC installation: /usr/lib64/gcc/x86_64-pc-linux-gnu/14.1.1
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
 "/usr/bin/ld" -export-dynamic -s --eh-frame-hdr -m elf_x86_64 -export-dynamic -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o jank /usr/lib64/gcc/x86_64-pc-linux-gnu/14.1.1/../../../../lib64/crt1.o /usr/lib64/gcc/x86_64-pc-linux-gnu/14.1.1/../../../../lib64/crti.o /usr/lib64/gcc/x86_64-pc-linux-gnu/14.1.1/crtbegin.o -Lbuild/cling-build/build-compiler-rt/lib/linux -L/usr/lib64/gcc/x86_64-pc-linux-gnu/14.1.1 -L/usr/lib64/gcc/x86_64-pc-linux-gnu/14.1.1/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/home/mateo/jank/compiler+runtime/build/cling-build/bin/../lib -L/lib -L/usr/lib --export-dynamic -lc++abi CMakeFiles/jank_exe.dir/src/cpp/main.cpp.o -rpath /home/mateo/jank/compiler+runtime/build: --whole-archive libjank.a --no-whole-archive --whole-archive libnanobench.a --no-whole-archive libfolly.a libjankcling.so vcpkg_installed/x64-clang-static/lib/libfmt.a vcpkg_installed/x64-clang-static/lib/libcord.a vcpkg_installed/x64-clang-static/lib/libgccpp.a vcpkg_installed/x64-clang-static/lib/libgctba.a vcpkg_installed/x64-clang-static/lib/libgc.a -ldl vcpkg_installed/x64-clang-static/lib/libzippp_static.a vcpkg_installed/x64-clang-static/lib/libzip.a vcpkg_installed/x64-clang-static/lib/libbz2.a vcpkg_installed/x64-clang-static/lib/libcrypto.a -ldl vcpkg_installed/x64-clang-static/lib/libz.a vcpkg_installed/x64-clang-static/lib/libCLI11.a -lreadline vcpkg_installed/x64-clang-static/lib/libboost_filesystem.a vcpkg_installed/x64-clang-static/lib/libboost_system.a vcpkg_installed/x64-clang-static/lib/libboost_atomic.a -lc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib64/gcc/x86_64-pc-linux-gnu/14.1.1/crtend.o /usr/lib64/gcc/x86_64-pc-linux-gnu/14.1.1/../../../../lib64/crtn.o
/usr/bin/ld: vcpkg_installed/x64-clang-static/lib/libCLI11.a(Precompile.cpp.o): undefined reference to symbol '_ZNSt14basic_ifstreamIcSt11char_traitsIcEEC1ERKNSt7__cxx1112basic_stringIcS1_SaIcEEESt13_Ios_Openmode@@GLIBCXX_3.4.21'
/usr/bin/ld: /usr/lib/libstdc++.so.6: error adding symbols: DSO missing from command line
clang-13: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

At this point, I'm out of ideas. Not sure how to proceed. Eventually, I would like to publish a package to the Arch User Repository in order to make trying out jank easier :)

Samy-33 commented 4 months ago

Here is an excerpt from my conversation with @jeaye. If your goal is to contribute to jank's compiler/runtime and not care strongly about running it on Arch, give distrobox a try.

So, I just saw this recently on my Arch distrobox as well. Unfortunately, there's no way around it right now. The problem is this: Cling is stuck using LLVM 13, which has some C++20 support. We're using that C++20 support by enabling -std=gnu++20 (gnu++20 vs c++20 grants us GNU extensions too).

HOWEVER, the latest GCC (pacman package gcc-libs) versions (14+) on Arch use a bunch of new C++20 features which Cling's old LLVM 13 just can't handle. But it's all still technically C++20. This leaves us with only two choices.

  • Stop using C++20 in jank, since we don't actually have good support for it on LLVM 13
  • Stop using Arch, since its C++20 headers are living too far in the future

We rely heavily on C++20 features, at this point. In particular, concepts. That's not something I can remove reasonably. So I changed my Arch distrobox to an Ubuntu 24.04 distrobox today and everything's back to working normally. But this will ultimately break when Ubuntu gets onto GCC 14.

This is yet another reason why we need to get off of Cling and onto upstream LLVM.

I also tried downgrading gcc-libs and relevant packages, but a whole bunch of other system packages rely on that and I broke everything and got my Arch into a state where even pacman didn't work. I had to manually untar the package files in my system in order to get things working again... so don't try that.

If you're not using distrobox already, definitely give it a go.

distrobox create --image ubuntu:24.04 jank

Then just distrobox enter jank whenever you want to develop. It'll keep you in the same directory with your same shell.

The doc/build.md file in the jank repo has the Ubuntu deps needed. Just copy/paste that guy in once you're in your distrobox. They're persistent, so you only need to do that once.

jeaye commented 4 months ago

Hey Mateo! Thanks for reporting. Thanks, Saket, for jumping in as well. As Saket said, jank can't build under Arch right now, due to Arch using a GCC version which is too shiny for Cling. This will be resolved once I can finish the migration to Clang 19 (blocked on a Clang bug right now).

Using libc++ (instead of libstdc++) isn't going to work unless you recompile ALL jank dependencies (include Cling/Clang/LLVM) using libc++. In my experience, this isn't feasible.

So, using distrobox, as Saket said I said, is the way forward for now! I'll leave this issue open until jank has finished the migration to Clang 19.

jeaye commented 4 months ago

This issue should be resolved, since the port to Clang 19 has been merged! Please delete (or back up) your build directories and go through the build.md doc again. If you hit any issues, let me know.