Build a share lib (.so) for all dependencies?


(Dan Tran) #1

I have a ‘legal’ requirement to build a Go module to produce an executable and all of its dependencies as a single .so. The exe contains our private Go code and dynamically link to open source packages as as single .so

Possible? how?

I am using Go 1.12.7 with GO111MODULE=on on SLES12

Very much appreciate any advice

-D


(Ivan Matmati) #2

Hi Dantran,

Wouldn’t it be what you’re looking for ? http://snowsyn.net/2016/09/11/creating-shared-libraries-in-go/
Have a nice day.


(Dan Tran) #3

I saw that post as well, and it not making sense to me :frowning: may be you can show a way to create a shared lib ( .so) against downloaded dependencies under GOPATH/pkg/mod?

Note, i am build my app with GOMOD


(Ivan Matmati) #4

Ok, I don’t know what could be messed with gomod but in first place, I would follow this article just to check what happens. So I’d follow the instructions given :

As you can see, the code has to be part of the main package, with an empty main function. The C package has to be imported. Exported functions must have the export annotation

And then build with

go build -o libimgutil.so -buildmode=c-shared yourfile.go

Could you try that ?


(Dan Tran) #5

wow, I am able to build my .so file at my module dir ( the one with go.mod)

go build -o libthirdparty.so  -buildmode=c-shared 

it creates a .so file with about 60M.

Now I need to produce my executable which i expect to be small

Any help is very much appreciated

-D


(Dan Tran) #6

just want to ping this group again, is there a way for me to build my own Go source and dynamically link to my thirdparties package produce by c-shared?