jssblck
jssblck

Reputation: 529

Binary-only library is not including dependencies

I'm attempting to build a binary-only library that includes some dependencies. The build of the binary-only library itself goes great, but it doesn't actually include my dependencies: when I try to use the library on a system without the dependencies installed, I am given an error saying they are missing.

For reference, the command I'm using to build the library is:

go build -o build/pkg/<os>_<arch>/<path/to/binary>.a

I then write my stub <library>.go file to build/src/<path/to/binary>.go.

The stub file contains stubbed implementations of all public methods and an import block for its dependencies, with each dependency included in that import block.

The stub file also has the // go:binary-only-package line above the package directive.

If there is a way to build a binary library that will include its dependencies I'd appreciate it!

Upvotes: 1

Views: 766

Answers (1)

Sean F
Sean F

Reputation: 4605

As you know, go compiles packages into individual archive files and creates a binary from those. Go recently allowed you to supply only the archives without the source code (normally go would recompile from source if the source is newer).

It is possible to combine several archives into one, as described here:

How to merge two "ar" static libraries into one

The problem is that go's compiler will find symbols using the folder and file structure that matches the package names. So, if you combine archives, the go compiler will no longer be able to locate symbols when building a binary. Only one of the packages will be locatable depending on the location of the archive. So it is not possible to do what you are requesting, at least with the current go compiler support.

Upvotes: 1

Related Questions