gccgo 4.9.2动态链接器错误:未定义引用`sync..import'

时间:2015-02-15 15:27:04

标签: gcc go gccgo

源代码是

package main
import "fmt"
func main() {
    fmt.Println("hello world")
}

构建对象文件时没有错误

root@OpenWrt:/mnt/sda3# gccgo -v -c hello.go
Using built-in specs.
COLLECT_GCC=gccgo
Target: mipsel-openwrt-linux-gnu
Configured with: /home/michal/Data/openwrt/mt7621/mtk-openwrt-master-eglibc/build_dir/target-mipsel_1004kc+dsp_eglibc-2.19/gcc-4.9.2/configure --target=mipsel-openwrt-linux --host=mipsel-openwrt-linux --build=x86_64-linux-gnu --program-prefix= --program-suffix= --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib --sysconfdir=/etc --datadir=/usr/share --localstatedir=/var --mandir=/usr/man --infodir=/usr/info --disable-nls --build=x86_64-linux-gnu --host=mipsel-openwrt-linux-gnu --target=mipsel-openwrt-linux-gnu --enable-languages=c,c++,go --with-bugurl=https://dev.openwrt.org/ --with-pkgversion='OpenWrt GCC 4.9.2' --enable-shared --disable-__cxa_atexit --enable-target-optspace --with-gnu-ld --disable-nls --disable-libmudflap --disable-multilib --disable-libgomp --disable-libquadmath --disable-libssp --disable-decimal-float --disable-libstdcxx-pch --with-host-libstdcxx=-lstdc++ --prefix=/usr --libexecdir=/usr/lib --with-float=soft
Thread model: posix
gcc version 4.9.2 (OpenWrt GCC 4.9.2) 
COLLECT_GCC_OPTIONS='-v' '-c' '-o' 'hello.o' '-shared-libgcc' '-msoft-float' '-mllsc' '-mno-shared'
 /usr/lib/gcc/mipsel-openwrt-linux-gnu/4.9.2/go1 hello.go -quiet -dumpbase hello.go -msoft-float -mllsc -mno-shared -auxbase-strip hello.o -version -L/usr/lib/gcc/mipsel-openwrt-linux-gnu/4.9.2 -L/usr/lib/gcc/mipsel-openwrt-linux-gnu/4.9.2/../../.. -o /tmp/ccWiioSJ.s
GNU Go (OpenWrt GCC 4.9.2) version 4.9.2 (mipsel-openwrt-linux-gnu)
        compiled by GNU C version 4.8.3, GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=47 --param ggc-min-heapsize=31962
GNU Go (OpenWrt GCC 4.9.2) version 4.9.2 (mipsel-openwrt-linux-gnu)
        compiled by GNU C version 4.8.3, GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=47 --param ggc-min-heapsize=31962
COLLECT_GCC_OPTIONS='-v' '-c' '-o' 'hello.o' '-shared-libgcc' '-msoft-float' '-mllsc' '-mno-shared'
 as -v -EL -O1 -no-mdebug -mabi=32 -mno-shared -KPIC -o hello.o /tmp/ccWiioSJ.s
GNU assembler version 2.24 (mipsel-openwrt-linux-gnu) using BFD version (GNU Binutils) 2.24
COMPILER_PATH=/usr/lib/gcc/mipsel-openwrt-linux-gnu/4.9.2/:/usr/lib/gcc/mipsel-openwrt-linux-gnu/4.9.2/:/usr/lib/gcc/mipsel-openwrt-linux-gnu/:/usr/lib/gcc/mipsel-openwrt-linux-gnu/4.9.2/:/usr/lib/gcc/mipsel-openwrt-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/mipsel-openwrt-linux-gnu/4.9.2/:/usr/lib/gcc/mipsel-openwrt-linux-gnu/4.9.2/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-c' '-o' 'hello.o' '-shared-libgcc' '-msoft-float' '-mllsc' '-mno-shared'

但链接器报告错误undefined reference to `sync..import'

root@OpenWrt:/mnt/sda2# gccgo -v -o hello hello.o
Using built-in specs.
COLLECT_GCC=gccgo
COLLECT_LTO_WRAPPER=/usr/lib/gcc/mipsel-openwrt-linux-gnu/4.9.2/lto-wrapper
Target: mipsel-openwrt-linux-gnu
Configured with: /home/michal/Data/openwrt/mt7621/mtk-openwrt-master-eglibc/build_dir/target-mipsel_1004kc+dsp_eglibc-2.19/gcc-4.9.2/configure --target=mipsel-openwrt-linux --host=mipsel-openwrt-linux --build=x86_64-linux-gnu --program-prefix= --program-suffix= --prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/lib --sysconfdir=/etc --datadir=/usr/share --localstatedir=/var --mandir=/usr/man --infodir=/usr/info --disable-nls --build=x86_64-linux-gnu --host=mipsel-openwrt-linux-gnu --target=mipsel-openwrt-linux-gnu --enable-languages=c,c++,go --with-bugurl=https://dev.openwrt.org/ --with-pkgversion='OpenWrt GCC 4.9.2' --enable-shared --disable-__cxa_atexit --enable-target-optspace --with-gnu-ld --disable-nls --disable-libmudflap --disable-multilib --disable-libgomp --disable-libquadmath --disable-libssp --disable-decimal-float --disable-libstdcxx-pch --with-host-libstdcxx=-lstdc++ --prefix=/usr --libexecdir=/usr/lib --with-float=soft
Thread model: posix
gcc version 4.9.2 (OpenWrt GCC 4.9.2) 
COMPILER_PATH=/usr/lib/gcc/mipsel-openwrt-linux-gnu/4.9.2/:/usr/lib/gcc/mipsel-openwrt-linux-gnu/4.9.2/:/usr/lib/gcc/mipsel-openwrt-linux-gnu/:/usr/lib/gcc/mipsel-openwrt-linux-gnu/4.9.2/:/usr/lib/gcc/mipsel-openwrt-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/mipsel-openwrt-linux-gnu/4.9.2/:/usr/lib/gcc/mipsel-openwrt-linux-gnu/4.9.2/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-o' 'hello' '-shared-libgcc' '-msoft-float' '-mllsc' '-mno-shared'
 /usr/lib/gcc/mipsel-openwrt-linux-gnu/4.9.2/collect2 --eh-frame-hdr -EL -dynamic-linker /lib/ld.so.1 -o hello /usr/lib/gcc/mipsel-openwrt-linux-gnu/4.9.2/crt1.o /usr/lib/gcc/mipsel-openwrt-linux-gnu/4.9.2/crti.o /usr/lib/gcc/mipsel-openwrt-linux-gnu/4.9.2/crtbegin.o -L/usr/lib/gcc/mipsel-openwrt-linux-gnu/4.9.2 -L/usr/lib/gcc/mipsel-openwrt-linux-gnu/4.9.2/../../.. hello.o -lgobegin -lgo -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/mipsel-openwrt-linux-gnu/4.9.2/crtend.o /usr/lib/gcc/mipsel-openwrt-linux-gnu/4.9.2/crtn.o
hello.o: In function `__go_init_main':
hello.go:(.text+0x16c): undefined reference to `sync..import'
collect2: error: ld returned 1 exit status

我错过了什么?谢谢你的帮助

我已经尝试过静态链接程序,添加一个标记-static-libgo,它可以工作。

1 个答案:

答案 0 :(得分:1)

动态链接充其量只是支持,并不是所有支持的,所以请耐心等待。

话虽如此,它对我有用,所以你的gcc和/或libgo设置可能有问题。

➜ gccgo -c hello.go 
➜ gccgo -o hello hello.o 
➜ ./hello 
hello world
➜ ldd hello
        linux-vdso.so.1 (0x00007fffb831f000)
        libgo.so.5 => /usr/lib/libgo.so.5 (0x00007f214aaba000)
        libm.so.6 => /usr/lib/libm.so.6 (0x00007f214a7b5000)
        libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007f214a59f000)
        libc.so.6 => /usr/lib/libc.so.6 (0x00007f214a1fc000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f214b919000)
        libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007f2149fdf000)
➜ gccgo -v
Using built-in specs.
COLLECT_GCC=gccgo
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-unknown-linux-gnu/4.9.2/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: /build/gcc-multilib/src/gcc-4.9-20150204/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-cloog-backend=isl --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-multilib --disable-werror --enable-checking=release
Thread model: posix
gcc version 4.9.2 20150204 (prerelease) (GCC)

如果您尝试获得较小的可执行文件大小,请考虑使用upx作为解决方法或尝试手动编译gccgo。