In a golang project building with gcc, how to statically link a library on macos?

585 Views Asked by At

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.

0

There are 0 best solutions below