Go - Cross compiling with CGO using xgo library

1.4k views Asked by At

I'm trying to compile a GO application, which uses the gokiri library. I installed docker and compiled locally the xgo cross compiler for go. When trying to execute the following command:

./xgo mydomain.com/test/test-app

I get the following error:

In file included from /usr/include/libxml2/libxml/parser.h:810:0,
             from /usr/include/libxml2/libxml/globals.h:18,
             from /usr/include/libxml2/libxml/threads.h:35,
             from /usr/include/libxml2/libxml/xmlmemory.h:218,
             from /usr/include/libxml2/libxml/tree.h:1307,
             from ../../github.com/moovweb/gokogiri/help/help.go:6:
/usr/include/libxml2/libxml/encoding.h:28:19: fatal error: iconv.h: No such file or directory

I've installed xcode-tools which helped me compile it for my machine (mac ox El Capitan). BUT, I cannot get it compiled to other environment.

Any help will be appreciated. Thanks.

Update 1:

I've tried to add the dependency, but got the same result:

./xgo --deps /usr/local/Cellar/libiconv/1.14/ mydomain.com/test/test-app

It was even mentioned in the logs of the xgo that this library was already cached:

Dependency already cached: /Users/macuser/.xgo-cache/1.14.
1

There are 1 answers

0
Philip On

from the documentation:

It is assumed that the dependent C/C++ library is configure/make based, was properly prepared for cross compilation and is available as a tarball download (.tar, .tar.gz or .tar.bz2). Further plans include extending this to cmake based projects, if need arises (please open an issue if it's important to you).

Such dependencies can be added via the --deps argument. They will be retrieved prior to starting the cross compilation and the packages cached to save bandwidth on subsequent calls.

So in this example, it would be:

./xgo --deps https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz mydomain.com/test/test-app