1

I've just compiled GCC from source, which gave me a libgccjit.so file to dynamically include from my program. However, perhaps I wouldn't want to bundle the file alongside the program if I were to give it to someone else. How do I statically include libgccjit?

  • I've tried using -static in GCC, but that doesn't see the .so file ("cannot find -lgccjit: No such file or directory").
  • I've tried using --enable-static and even --disable-shared when compiling GCC, but somehow that doesn't actually give me the libgccjit.a file I need.
  • I've tried packaging the .o files included in libgccjit.so manually via ar, but that explodes, filling my terminal with an absolutely massive amount of undefined reference errors, probably because the files were made in C++ and not C.
13
  • However, perhaps I wouldn't want to bundle the file alongside the program if I were to give it to someone else. Not, perhaps, a sufficient reason. gcc creates a .so for a [whatever] reason (It does use .a when needed). Instead of just doing the easy thing of shipping the .so (or not shipping a custom gcc at all), this is [seems like] an artificial (and problematic--as you found out!) restriction. It's easy enough to ship the .so (or ship everything in a [docker] container). Commented May 4 at 20:08
  • Also, when you (cross) build for windows, you'll get a .dll instead. You'll have to do a full rebuild anyway because windows PE format files and [linux] ELF files aren't compatible. Neither are the ABIs (what function call args are passed in what H/W registers). And, the syscall mechanisms are different. Again, you probably want a container. Or, put everything under your own top level directory (e.g. /usr/local/mystuff/{bin,lib,man}) including all your non-standard gcc files. Commented May 4 at 20:18
  • Again, why have a custom gcc at all? Will it have a custom libc as well to fit the target system? To my mind, the only reason for this is that (e.g.) libgccjit.so is not built/shipped by default for most distros. So, can you ship just libgccjit.so or do you need a number of other [compatible] files as well (e.g. libgcc.a)? What other libraries/source [that you design/create] are providing the real value? (e.g.) "I wrote a matrix multiply library that is 20% faster". This is not a new problem. I'd look at existing packages that solve similar problems. Commented May 4 at 20:27
  • @CraigEstey What do you mean a "custom" GCC? You emphasize it quite a bit, but all I did was download the very standard GCC source and compiled it for libgccjit using the instructions on their website. And what does it matter what I'm working on? It isn't relevant for the question. Commented May 4 at 21:03
  • 1
    I couldn't find a stated reason for distributing libgccjit only as a shared library. Note that you will effectively link in entire GCC, and your resulting program will be covered by GPL. As for packaging all the *.o files -- surely you can look at the link line for libgccjit.so and use the same object files and libraries to link it all statically into your binary. Finally, libgccjit.so documentation mentions that it links in libbackend.a where most of the compiler "lives"; perhaps you didn't link that? Commented May 7 at 2:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.