Golang Go语言中 交叉编译报错:libgcc_s.so.1: 版本`GCC_4.2.0'未找到(文件 helloworld 必需的) -- /tank/obsnew/lib/libgcc_s.so.1: 错误的 ELF 类型: ELFCLASS32

发布于 1周前 作者 nodeper 来自 Go语言

从 Linux 64 位( Redhat 6.5 )交叉编译生成 Solaris 5.10 目标可执行程序,golang 语言打印一个 hello world,先从 Solaris 拷贝了头文件和库文件到红帽,再编译 binutils,再编译 gcc-5.1.0,生成 sparc-sun-solaris2.10-gccgo

拷贝到 Solaris 后执行报错:

t5240-1:/tank/obsnew/yinq/shandonglt% ./helloworld
ld.so.1: helloworld: 致命的: libgcc_s.so.1: 版本`GCC_4.2.0'未找到(文件 helloworld 必需的)
ld.so.1: helloworld: 致命的: /tank/obsnew/lib/libgcc_s.so.1: 错误的 ELF 类型:ELFCLASS32
被杀掉

ldd 和 Solarisgcc 版本:

t5240-1:/tank/obsnew/yinqq/lt% ldd aiReqResend
		libnsl.so.1 =>   /lib/64/libnsl.so.1
		libsocket.so.1 =>        /lib/64/libsocket.so.1
		librt.so.1 =>    /lib/64/librt.so.1
		libpthread.so.1 =>       /lib/64/libpthread.so.1
		libm.so.2 =>     /lib/64/libm.so.2
		libgcc_s.so.1 =>         /usr/local/lib/sparcv9/libgcc_s.so.1
		libgcc_s.so.1 (GCC_4.2.0) =>     (version not found)
		libc.so.1 =>     /lib/64/libc.so.1
		libmp.so.2 =>    /lib/64/libmp.so.2
		libmd.so.1 =>    /lib/64/libmd.so.1
		libscf.so.1 =>   /lib/64/libscf.so.1
		libaio.so.1 =>   /lib/64/libaio.so.1
		libdoor.so.1 =>  /lib/64/libdoor.so.1
		libuutil.so.1 =>         /lib/64/libuutil.so.1
		libgen.so.1 =>   /lib/64/libgen.so.1
		/platform/SUNW,T5240/lib/sparcv9/libc_psr.so.1
		/platform/SUNW,T5240/lib/sparcv9/libmd_psr.so.1
t5240-1:/tank/obsnew/yinqq/lt% file /usr/local/lib/sparcv9/libgcc_s.so.1
/usr/local/lib/sparcv9/libgcc_s.so.1: ELF 64-bit MSB dynamic library SPARCV9 version 1,dynamic linked,not striped
t5240-1:/tank/obsnew/yinq/shandonglt% gcc -v
Reading specs from /usr/local/lib/gcc/sparc-sun-solaris2.10/3.4.6/specs
Configured with: ../configure --with-as=/usr/ccs/bin/as --with-ld=/usr/ccs/bin/ld --enable-shared --enable-languages=c,c++,f77
Thread model: posix
gcc version 3.4.6

编译过程:

[y@M610-252126 aiReqResend]$ go build --compiler gccgo --gccgoflags "-v -static-libgo -Wl,-dy -lnsl -lsocket -lrt" aiReqResend.go
# parsing_config
Using built-in specs.
COLLECT_GCC=gccgo
Target: sparc-sun-solaris2.10
Configured with: ../gcc-5.1.0/configure --target=sparc-sun-solaris2.10 --with-gnu-as --with-gnu-ld --prefix=/home/y/opt/cross/ --with-sysroot=/home/y/opt/cross/sysroot/ --disable-libgcj --enable-languages=c,c++,go
Thread model: posix
gcc version 5.1.0 (GCC) 
COLLECT_GCC_OPTIONS='-I' '/tmp/go-build137487689' '-c' '-g' '-m64' '-fgo-pkgpath=parsing_config' '-fgo-relative-import-path=_/home/y/xsd_log_resend/src/parsing_config' '-o' '/tmp/go-build137487689/parsing_config/_obj/_go_.o' '-v' '-shared-libgcc'
 /home/y/opt/cross/libexec/gcc/sparc-sun-solaris2.10/5.1.0/go1 ../parsing_config/parsing_config.go -mptr64 -mstack-bias -mno-v8plus -mcpu=v9 -quiet -dumpbase parsing_config.go -m64 -auxbase-strip $WORK/parsing_config/_obj/_go_.o -g -version -fgo-pkgpath=parsing_config -fgo-relative-import-path=_/home/y/xsd_log_resend/src/parsing_config -I $WORK -L/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0/sparcv9 -L/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0/../../../../sparc-sun-solaris2.10/lib/sparcv9 -L/home/y/opt/cross/sysroot/lib/sparcv9 -L/home/y/opt/cross/sysroot/usr/lib/sparcv9 -L/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0 -L/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0/../../../../sparc-sun-solaris2.10/lib -L/home/y/opt/cross/sysroot/lib -L/home/y/opt/cross/sysroot/usr/lib -o /tmp/ccJntC1m.s
GNU Go (GCC) version 5.1.0 (sparc-sun-solaris2.10)
	compiled by GNU C version 4.4.7 20120313 (Red Hat 4.4.7-4), GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU Go (GCC) version 5.1.0 (sparc-sun-solaris2.10)
	compiled by GNU C version 4.4.7 20120313 (Red Hat 4.4.7-4), GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
COLLECT_GCC_OPTIONS='-I' '/tmp/go-build137487689' '-c' '-g' '-m64' '-fgo-pkgpath=parsing_config' '-fgo-relative-import-path=_/home/y/xsd_log_resend/src/parsing_config' '-o' '/tmp/go-build137487689/parsing_config/_obj/_go_.o' '-v' '-shared-libgcc'
 /home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0/../../../../sparc-sun-solaris2.10/bin/as -v -I $WORK -V -Qy -s -xarch=v9 -64 -no-undeclared-regs -o $WORK/parsing_config/_obj/_go_.o /tmp/ccJntC1m.s
GNU assembler version 2.25 (sparc-sun-solaris2.10) using BFD version (GNU Binutils) 2.25
COMPILER_PATH=/home/y/opt/cross/libexec/gcc/sparc-sun-solaris2.10/5.1.0/:/home/y/opt/cross/libexec/gcc/sparc-sun-solaris2.10/5.1.0/:/home/y/opt/cross/libexec/gcc/sparc-sun-solaris2.10/:/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0/:/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/:/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0/../../../../sparc-sun-solaris2.10/bin/
LIBRARY_PATH=/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0/sparcv9/:/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0/../../../../sparc-sun-solaris2.10/lib/sparcv9/:/home/y/opt/cross/sysroot/lib/sparcv9/:/home/y/opt/cross/sysroot/usr/lib/sparcv9/:/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0/:/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0/../../../../sparc-sun-solaris2.10/lib/:/home/y/opt/cross/sysroot/lib/:/home/y/opt/cross/sysroot/usr/lib/
COLLECT_GCC_OPTIONS='-I' '/tmp/go-build137487689' '-c' '-g' '-m64' '-fgo-pkgpath=parsing_config' '-fgo-relative-import-path=_/home/y/xsd_log_resend/src/parsing_config' '-o' '/tmp/go-build137487689/parsing_config/_obj/_go_.o' '-v' '-shared-libgcc'
# command-line-arguments
Using built-in specs.
COLLECT_GCC=gccgo
Target: sparc-sun-solaris2.10
Configured with: ../gcc-5.1.0/configure --target=sparc-sun-solaris2.10 --with-gnu-as --with-gnu-ld --prefix=/home/y/opt/cross/ --with-sysroot=/home/y/opt/cross/sysroot/ --disable-libgcj --enable-languages=c,c++,go
Thread model: posix
gcc version 5.1.0 (GCC) 
COLLECT_GCC_OPTIONS='-I' '/tmp/go-build137487689' '-I' '/home/y/xsd_log_resend/pkg/gccgo_linux_amd64' '-c' '-g' '-m64' '-fgo-relative-import-path=_/home/y/xsd_log_resend/src/aiReqResend' '-o' '/tmp/go-build137487689/command-line-arguments/_obj/_go_.o' '-v' '-shared-libgcc'
 /home/y/opt/cross/libexec/gcc/sparc-sun-solaris2.10/5.1.0/go1 ./aiReqResend.go -mptr64 -mstack-bias -mno-v8plus -mcpu=v9 -quiet -dumpbase aiReqResend.go -m64 -auxbase-strip $WORK/command-line-arguments/_obj/_go_.o -g -version -fgo-relative-import-path=_/home/y/xsd_log_resend/src/aiReqResend -I $WORK -I /home/y/xsd_log_resend/pkg/gccgo_linux_amd64 -L/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0/sparcv9 -L/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0/../../../../sparc-sun-solaris2.10/lib/sparcv9 -L/home/y/opt/cross/sysroot/lib/sparcv9 -L/home/y/opt/cross/sysroot/usr/lib/sparcv9 -L/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0 -L/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0/../../../../sparc-sun-solaris2.10/lib -L/home/y/opt/cross/sysroot/lib -L/home/y/opt/cross/sysroot/usr/lib -o /tmp/ccy4Riqt.s
GNU Go (GCC) version 5.1.0 (sparc-sun-solaris2.10)
	compiled by GNU C version 4.4.7 20120313 (Red Hat 4.4.7-4), GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU Go (GCC) version 5.1.0 (sparc-sun-solaris2.10)
	compiled by GNU C version 4.4.7 20120313 (Red Hat 4.4.7-4), GMP version 4.3.2, MPFR version 2.4.2, MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
COLLECT_GCC_OPTIONS='-I' '/tmp/go-build137487689' '-I' '/home/y/xsd_log_resend/pkg/gccgo_linux_amd64' '-c' '-g' '-m64' '-fgo-relative-import-path=_/home/y/xsd_log_resend/src/aiReqResend' '-o' '/tmp/go-build137487689/command-line-arguments/_obj/_go_.o' '-v' '-shared-libgcc'
 /home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0/../../../../sparc-sun-solaris2.10/bin/as -v -I $WORK -I /home/y/xsd_log_resend/pkg/gccgo_linux_amd64 -V -Qy -s -xarch=v9 -64 -no-undeclared-regs -o $WORK/command-line-arguments/_obj/_go_.o /tmp/ccy4Riqt.s
GNU assembler version 2.25 (sparc-sun-solaris2.10) using BFD version (GNU Binutils) 2.25
COMPILER_PATH=/home/y/opt/cross/libexec/gcc/sparc-sun-solaris2.10/5.1.0/:/home/y/opt/cross/libexec/gcc/sparc-sun-solaris2.10/5.1.0/:/home/y/opt/cross/libexec/gcc/sparc-sun-solaris2.10/:/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0/:/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/:/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0/../../../../sparc-sun-solaris2.10/bin/
LIBRARY_PATH=/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0/sparcv9/:/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0/../../../../sparc-sun-solaris2.10/lib/sparcv9/:/home/y/opt/cross/sysroot/lib/sparcv9/:/home/y/opt/cross/sysroot/usr/lib/sparcv9/:/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0/:/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0/../../../../sparc-sun-solaris2.10/lib/:/home/y/opt/cross/sysroot/lib/:/home/y/opt/cross/sysroot/usr/lib/
COLLECT_GCC_OPTIONS='-I' '/tmp/go-build137487689' '-I' '/home/y/xsd_log_resend/pkg/gccgo_linux_amd64' '-c' '-g' '-m64' '-fgo-relative-import-path=_/home/y/xsd_log_resend/src/aiReqResend' '-o' '/tmp/go-build137487689/command-line-arguments/_obj/_go_.o' '-v' '-shared-libgcc'
# command-line-arguments
Using built-in specs.
COLLECT_GCC=gccgo
COLLECT_LTO_WRAPPER=/home/y/opt/cross/libexec/gcc/sparc-sun-solaris2.10/5.1.0/lto-wrapper
Target: sparc-sun-solaris2.10
Configured with: ../gcc-5.1.0/configure --target=sparc-sun-solaris2.10 --with-gnu-as --with-gnu-ld --prefix=/home/y/opt/cross/ --with-sysroot=/home/y/opt/cross/sysroot/ --disable-libgcj --enable-languages=c,c++,go
Thread model: posix
gcc version 5.1.0 (GCC) 
COMPILER_PATH=/home/y/opt/cross/libexec/gcc/sparc-sun-solaris2.10/5.1.0/:/home/y/opt/cross/libexec/gcc/sparc-sun-solaris2.10/5.1.0/:/home/y/opt/cross/libexec/gcc/sparc-sun-solaris2.10/:/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0/:/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/:/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0/../../../../sparc-sun-solaris2.10/bin/
LIBRARY_PATH=/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0/sparcv9/:/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0/../../../../sparc-sun-solaris2.10/lib/sparcv9/:/home/y/opt/cross/sysroot/lib/sparcv9/:/home/y/opt/cross/sysroot/usr/lib/sparcv9/:/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0/:/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0/../../../../sparc-sun-solaris2.10/lib/:/home/y/opt/cross/sysroot/lib/:/home/y/opt/cross/sysroot/usr/lib/
COLLECT_GCC_OPTIONS='-o' 'aiReqResend' '-m64' '-v' '-shared-libgcc'
 /home/y/opt/cross/libexec/gcc/sparc-sun-solaris2.10/5.1.0/collect2 -plugin /home/y/opt/cross/libexec/gcc/sparc-sun-solaris2.10/5.1.0/liblto_plugin.so -plugin-opt=/home/y/opt/cross/libexec/gcc/sparc-sun-solaris2.10/5.1.0/lto-wrapper -plugin-opt=-fresolution=/tmp/cccfnQ4K.res -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc --sysroot=/home/y/opt/cross/sysroot/ -V -m elf64_sparc_sol2 -Y P,/home/y/opt/cross/sysroot//lib/sparcv9:/home/y/opt/cross/sysroot//usr/lib/sparcv9 -Qy -o aiReqResend /home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0/sparcv9/crt1.o /home/y/opt/cross/sysroot/usr/lib/sparcv9/crti.o /home/y/opt/cross/sysroot/usr/lib/sparcv9/values-Xa.o /home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0/sparcv9/crtbegin.o -L/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0/sparcv9 -L/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0/../../../../sparc-sun-solaris2.10/lib/sparcv9 -L/home/y/opt/cross/sysroot/lib/sparcv9 -L/home/y/opt/cross/sysroot/usr/lib/sparcv9 -L/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0 -L/home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0/../../../../sparc-sun-solaris2.10/lib -L/home/y/opt/cross/sysroot/lib -L/home/y/opt/cross/sysroot/usr/lib $WORK/command-line-arguments/_obj/_go_.o -( $WORK/libparsing_config.a -E -) -dy -lnsl -lsocket -lrt -lgobegin -Bstatic -lgo -Bdynamic -lpthread -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc -lc /home/y/opt/cross/lib/gcc/sparc-sun-solaris2.10/5.1.0/sparcv9/crtend.o /home/y/opt/cross/sysroot/usr/lib/sparcv9/crtn.o
GNU ld (GNU Binutils) 2.25
  Supported emulations:
   elf32_sparc_sol2
   elf32_sparc
   elf64_sparc_sol2
   elf64_sparc
[y@M610-252126 aiReqResend]$ ll
total 8168
-rwxrwxr-x 1 y y 8350856 Oct 12 19:45 aiReqResend
-rw-rw-r-- 1 y y 8610 Oct  9 15:14 aiReqResend.go

Golang Go语言中 交叉编译报错:libgcc_s.so.1: 版本`GCC_4.2.0'未找到(文件 helloworld 必需的) -- /tank/obsnew/lib/libgcc_s.so.1: 错误的 ELF 类型: ELFCLASS32

更多关于Golang Go语言中 交叉编译报错:libgcc_s.so.1: 版本`GCC_4.2.0'未找到(文件 helloworld 必需的) -- /tank/obsnew/lib/libgcc_s.so.1: 错误的 ELF 类型: ELFCLASS32的实战系列教程也可以访问 https://www.itying.com/category-94-b0.html

3 回复

libgcc_s.so.1 (GCC_4.2.0) => (version not found) 说明了对应版本的 so 库找不到。你的系统存在 libgcc_s.so.1 这个库,但与编译 aiReqResend 这个程序时的版本(4.2.0)不兼容。

你应该在当前系统重新编译一次这个程序,或者把 4.2.0 版本的拷过来共存(即使能用也有可能存在未知的问题)

更多关于Golang Go语言中 交叉编译报错:libgcc_s.so.1: 版本`GCC_4.2.0'未找到(文件 helloworld 必需的) -- /tank/obsnew/lib/libgcc_s.so.1: 错误的 ELF 类型: ELFCLASS32的实战系列教程也可以访问 https://www.itying.com/category-94-b0.html


谢谢 changnet 深夜回复

在Go语言中进行交叉编译时遇到关于libgcc_s.so.1的错误,通常是因为目标平台与编译平台在架构或GCC版本上存在差异。错误信息中提到的“错误的 ELF 类型:ELFCLASS32”表明你尝试在64位系统上编译或运行一个32位的库。

解决这个问题的步骤如下:

  1. 确认目标平台:首先明确你的目标平台是32位还是64位,以及对应的操作系统类型(如Linux、macOS等)。

  2. 设置正确的交叉编译环境:确保你的编译环境(包括Go编译器和任何必要的C库)是针对目标平台的。例如,如果你是在64位Linux上编译32位二进制文件,需要安装32位的编译工具和库。

  3. 安装或更新GCC:错误中提到GCC_4.2.0版本未找到,可能需要安装或更新GCC到一个兼容的版本。使用如apt-get install gcc:i386(对于Debian/Ubuntu)或相应的命令来安装32位GCC库。

  4. 使用静态链接:如果问题依旧,尝试在Go编译时使用静态链接,这可以避免依赖动态库。可以通过设置环境变量CGO_ENABLED=0来禁用cgo,从而强制Go使用静态链接。

  5. 重新编译:在调整了环境后,重新进行交叉编译。

如果上述步骤仍然无法解决问题,建议检查具体的交叉编译命令和环境配置,确保所有路径和设置都正确无误。

回到顶部