Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gccgo on Precise

When trying to link with gccgo on Precise, I get this linking error:

matt@matt-1005P:~/src/gopath/src/meme$ gccgo cmd/meme/main.go -o meme
/usr/bin/ld: cannot find -lgcc_s
collect2: error: ld returned 1 exit status

There are reports of this error, but no clean solutions. How do I fix it?

gccgo (Ubuntu/Linaro 4.7.0-0ubuntu4) 4.7.0

Linux matt-1005P 3.2.0-24-generic-pae #38-Ubuntu SMP Tue May 1 16:40:26 UTC 2012 i686 i686 i386 GNU/Linux

like image 549
Matt Joiner Avatar asked May 14 '12 06:05

Matt Joiner


2 Answers

This was recently brought up on the golang-nuts group: compiling with gccgo from packaged binaries.

It's a known issue in Ubuntu (Bug #966570). To work around it, you can link with the static libgcc by specifying -static-libgcc in the gccgoflags. i.e.

go build -compiler gccgo -gccgoflags '-static-libgcc'
like image 68
axw Avatar answered Sep 29 '22 05:09

axw


From what I can tell, it's because gccgo is based on GCC 4.7, but Precise uses GCC 4.6 by default. For whatever reason, the library paths are incorrect, or the package is incomplete because it's missing libgcc_s.

I located possible libraries with find / -name 'libgcc_s*' and passed the library path like so:

go install -compiler=gccgo -gccgoflags -L/usr/lib/gcc/i686-linux-gnu/4.6 meme/cmd/meme

Note that this is linking against 4.6's libgcc_s, but seems to work anyway.

like image 40
Matt Joiner Avatar answered Sep 29 '22 04:09

Matt Joiner