9

While build Go program with use of Cgo I get error

/usr/lib/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: /tmp/go-link-373355991/000002.o: unrecognized relocation (0x2a) in section `.text'
/usr/bin/ld: final link failed: Bad value
collect2: error: ld returned 1 exit status

Tried to google that issue and found some bugs (https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=808205) on Debian and Ubuntu with C compiler and linker in versions of libc6 (2.21) which are newer than version I use (2.19).

Also there mentioned having problems compiling C programs and I compile example in C successfully.

I tried to build my Go program on other machine with same system and libraries versions and the build succeeded.

Igor
  • 93
  • 1
  • 5
  • It may be easier to answer your question if you post the code. Also, what type of architecture and OS was it where the build succeeded? – ijt Mar 05 '17 at 06:21
  • 2
    I had the same problem with GLFW but with c++/c, my issue was that the version of the compiler I used to compile with was different than the version used to compile the library I was linking against. – Krupip Jul 07 '17 at 20:47

2 Answers2

2

check if you are not using ccache. ie by : echo $PATH if something like /usr/local/ccache path comes first... be aware! ccache try to optimize compilation time, using a cache. If you have build a lib with a first compiler and then trying to compile with another, you are expose to such relocation trouble.

so try to clear the ccache : ccache -C or simply edit your PATH removing the path dedicated to ccache by export PATH=/usr/bin: ...

A++ Thilas

Thilas
  • 21
  • 3
1

Remove files in the GOCACHE, then go build again.

$go env

GOCACHE="~/.cache/go-build"

...

$ rm -rf ~/.cache/go-build/*

Junmei.D
  • 41
  • 3