'go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1 /usr/bin/ld: cannot find -lgdal

I am trying to run go build on my sources.

go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: cannot find -lgdal
collect2: error: ld returned 1 exit status

My LD_LIBRARY_PATH variable contains /home/fzd/project/lib64, the path to the dir of the libgdal.so file. My PKG_CONFIG_PATH contains the path to the dir of a .pc file with the following contents :

prefix=/home/fzd/project
exec_prefix=${prefix}
libdir=${prefix}/lib64
deplibdir=${prefix}/lib64
includedir=${prefix}/include

Name: myLibs
Description: Libs
Requires:
Version: v1.0
Libs: -L${deplibdir} -lgdal
Cflags: -I${includedir}

I don't know which variable to check. Everything seems fine, and the fun part is that, when I clone my repo elsewhere, I don't have the issue (same LD_LIBRARY_PATH, etc.)

Does anyone have a clue about what I could check?

I am using go1.11.1, on CentOS7.6.



Solution 1:[1]

Here are a few things I did to solve this issue:

  • rm -rf ~/.cache/go-build : this contained a few build artifacts
  • rm -rf ${MyProject}/{bin,pkg} : for the same reason

Solution 2:[2]

try yum install glibc-static.x86_64 -y

I've came across the error like

/usr/local/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: cannot find -ldl
/usr/bin/ld: cannot find -lpthread

and the glibc-static lib fix it.

Solution 3:[3]

The following steps worked for me:

yum install glibc-static.x86_64 libstdc++-static -y

And then removing last build cache

rm -rf ~/.cache/go-build

And then exporting CXXFLAGS

export CXXFLAGS="-stdlib=libstdc++" CC=/usr/bin/gcc CXX=/usr/bin/g++

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 fzd
Solution 2 hukeping
Solution 3 kadi-dz