Go语言 cgo openwrt sdk 交叉编译报错 collect2: fatal error: cannot find ‘ld‘的解决办法

使用openwrt sdk交叉编译arm时报错如下

CGO_ENABLED=1 GOOS=linux GOARCH=arm GOARM=6 CC=arm-openwrt-linux-gcc CXX=arm-openwrt-linux-g++ AR=arm-openwrt-linux-ar go build -ldflags="-s -w" -o artifacts/zbpd-openwrt-linux-arm1176jzf-s+vfp
......
/usr/local/go/pkg/tool/linux_amd64/link: running arm-openwrt-linux-gcc failed: exit status 1
collect2: fatal error: cannot find 'ld'
compilation terminated.

原因是该工具链没有ld.gold而只有ld.bfd,因此添加环境变量

export CGO_CFLAGS=$CGO_CFLAGS" -fuse-ld=bfd"
export CGO_LDFLAGS=$CGO_LDFLAGS" -fuse-ld=bfd"
export GOGCCFLAGS=$GOGCCFLAGS" -fuse-ld=bfd"

之后编译则无报错。
另外,使用该sdk编译时,还需要设置STAGING_DIRPATH

PATH=$PATH:`pwd`/op19078-brcm2708/staging_dir/toolchain-arm_arm1176jzf-s+vfp_gcc-7.5.0_musl_eabi/bin/
export PATH
export STAGING_DIR=`pwd`/op19078-brcm2708/staging_dir/toolchain-arm_arm1176jzf-s+vfp_gcc-7.5.0_musl_eabi/

猜你喜欢

转载自blog.csdn.net/u011570312/article/details/120781681