Go multiplatform library from one package

405 Views Asked by At

The problem

I am trying to create a multiplatform library, including native mobile, with Go. Using build commands I am able to create different kind formats with various degrees of success. With cgo I can build [.a,.h,.so,.lib,.dll] instead with gomobile [.aar,.jar,.framework].

The problem i am facing is that cgo requires that the code of the library is in the main package and gomobile requires that code is on a differrent package than main.

If i try to build the main package with gomobile I get:

binding "main" package (golib) is not supported

Instead if I try to build with cgo a package that isn't the main one:

-buildmode=c-shared requires exactly one main package

or

-buildmode=c-archive requires exactly one main package

I am using this commands:

Shared library

go build -buildmode=c-shared -o libraries\golibs.dll

go build -buildmode=c-shared -o libraries\golibs.so

Static library

go build -buildmode=c-archive -o libraries\golibs.lib

go build -buildmode=c-archive -o libraries\golibs.a

Android

gomobile bind -target=android -androidapi 19 -o libraries\mobile\golibs.aar -v .\golibs

Desired Result

How i can evade duplicate my library?

I want to have just one package (main or not) for my library.

0

There are 0 best solutions below