源代码是
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
,它可以工作。