building GOARCH=386 c-shared library using gccgo

150 views
Skip to first unread message

Adyuor

unread,
Sep 11, 2015, 8:09:33 PM9/11/15
to golang-nuts

Hello,

I have been googling to figure out a way to build 32 bit x86 c-shared libraries on linux platform using gccgo. The go build command only seems to support linux/x64 architecture on go1.5 but some online articles suggest it can be done by using gccgo directly. I have tried installing gccgo and building libraries but have not been very successful in running the c-shared example showed inhttp://blog.ralch.com/tutorial/golang-sharing-libraries/ (loading a c-shared lib in a c program). I get this error "fatal error: cgo callback before cgo call". The go build command also has a dependency on libgolibbegin.so but I could not find it anywhere. Can anyone give pointers on how to achieve this mode ?

Thanks !!

Ian Lance Taylor

unread,
Sep 11, 2015, 8:25:18 PM9/11/15
to Adyuor, golang-nuts
The go command should support -buildmode=c-shared just fine if you use
-compiler=gccgo.

libgolibbegin was added to gccgo in GCC 5, so you need to have a fully
up to date version of gccgo. Using a correct libgolibbegin should fix
the "cgo callback before cgo call" problem.

Ian

Adyuor

unread,
Sep 11, 2015, 11:06:39 PM9/11/15
to golang-nuts, aditya...@gmail.com
Hello Ian,

I have gccgo version 5.0.0 installed (downloaded and built from svn://gcc.gnu.org/svn/gcc/branches/gccgo).
The built libraries do not include libgolibbegin.so ( I do see a libgobegin.a ). Is there another source for a newer GCC version ?

Also when I set GOARCH=386, go build -compiler=gccgo gives following error:
can't load package: no buildable Go source files in <CURDIR>
With GOARCH set to amd64, I do not see any error except for the linker error for libgolibgebgin.so

My go version is go1.5 linux/amd64

Thanks !!

Ian Lance Taylor

unread,
Sep 12, 2015, 2:06:38 PM9/12/15
to Adyuor, golang-nuts
On Fri, Sep 11, 2015 at 8:06 PM, Adyuor <aditya...@gmail.com> wrote:
>
> I have gccgo version 5.0.0 installed (downloaded and built from
> svn://gcc.gnu.org/svn/gcc/branches/gccgo).
> The built libraries do not include libgolibbegin.so ( I do see a
> libgobegin.a ). Is there another source for a newer GCC version ?

Hmmm, looks like the first release it got into was 5.2. Sorry about
the incorrect suggestion that it was in GCC 5.0.

> Also when I set GOARCH=386, go build -compiler=gccgo gives following error:
> can't load package: no buildable Go source files in <CURDIR>
> With GOARCH set to amd64, I do not see any error except for the linker error
> for libgolibgebgin.so

The GOARCH issue sounds like an entirely different problem. I don't
know what is going on there. That usually means that build
constraints are ruling out all of the available files.

Ian
Reply all
Reply to author
Forward
0 new messages