0

I am making a very small application in golang that happens to encode mp3's. For that I am using the go-lame package that is a go binding to libmp3lame.

I want to distribute this small piece of app to my users without needing them to install anything more, so I want to statically build my project.

I can do that just fine on linux, passing the static flag to the gcc compiler.

But on macos (here on a M1 machine, but that is irrelevant) I cannot statically build the app as lcrt0.o is missing - something that is normal as I saw on SO, because you pretty much cannot statically link a program on macOS, there's going to be a couple of dynamic system lib forced on you.

For my use case this is fine, but i'd like lame to be statically linked and offer a nice distribution experience to the users.

So, here is my question : how can I build my project so that the compilers statically links libmp3lame in my executable but without statically link the other system libs.

olup otilapan
  • 464
  • 4
  • 13
  • This would need to be handled by the compiler linking the final executable. See https://stackoverflow.com/questions/30969816/gcc-compilation-with-linker-differences, or https://stackoverflow.com/questions/38785691/trying-to-build-static-cgo-executable-with-oracle-libraries-on-linux-ubuntu for example – JimB Jun 30 '22 at 21:19
  • `Bstatic` seem to be what I am looking for, but not possible on macos's `ld` – olup otilapan Jun 30 '22 at 21:32
  • I just moved the `.dylib` files out of my lib directory, only leaving the `.a`, and the compiler took that and static'ed it. I would be gld for a more "argumenty" way of forcing gcc to take the `.a` file – olup otilapan Jun 30 '22 at 21:38
  • May be just specify full path of the .a file on linking command line. Like: "gcc … file.o /path/to/libfile.a" – mgagnon Jun 30 '22 at 23:58

0 Answers0