How to create statically linked SO in golang

I am trying to create a statically linked so for go package

go install -v --ldflags=-d -linkmode external --tags=purego netgo with_embed package_name

it creates package_name.a. I am trying to create package_name.so which should be statically linked. Can someone suggest?

.a files are statically linked libraries. .so files are dynamically linked.

If I take the object dump of .a file then it gives error
objdump: __.PKGDEF: File format not recognized
objdump: go.o: File format not recognized

I am trying to create a library file where “ldd libname” should display statically linked and objdump should work on it.

There is a difference between a static library (.a) and statically linked so

ldd static_library.a prints “not a dynamic executable”
ldd libname.so prints statically linked

I am trying the second one which can be load at run time by a process.

I think this is different. You have created a so using c-shared
ldd libso.so should print
statically linked

objdump for libso should also work.

If I create a binary using following command
go install -v --ldflags ‘-w -d -linkmode internal’ --tags ‘purego netgo with_embed’ mainpackage

ldd binaryname prints “not a dynamic executable” and objdump also works for it

What is the difference?

ldd static_library.a prints “not a dynamic executable”
ldd libname.so prints statically linked
objdump works for libname.so and not for static_library.a.
dlopen works for libname.so and not for static_library.a.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.