为什么在Debian 9中编译的golang二进制文件不能在Centos 7中启动?

时间:2018-10-03 21:10:46

标签: go

在Debian 9上编译了一个应用程序,当我尝试在CentosOS上运行时,我得到了

./app: /lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by ./app)
./app: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by ./app)
./app: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by ./app)

ldd ./app show

bash-4.2$ ldd app 
./app: /lib64/libstdc++.so.6: version `CXXABI_1.3.8' not found (required by ./app)
./app: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by ./app)
./app: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by ./app)
    linux-vdso.so.1 =>  (0x00007fff24901000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f45a97ff000)
    libstdc++.so.6 => /lib64/libstdc++.so.6 (0x00007f45a94f8000)
    libm.so.6 => /lib64/libm.so.6 (0x00007f45a91f5000)
    libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f45a8fdf000)
    libc.so.6 => /lib64/libc.so.6 (0x00007f45a8c12000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f45a9a25000)

1 个答案:

答案 0 :(得分:3)

您的程序可能隐式使用cgo并生成一个可执行文件,该可执行文件取决于正在进行编译的主机的C++ ABI versions(Debian 9)。不幸的是,您的执行目标(CentOS 7)似乎具有不兼容的ABI。

您可以通过禁用cgo进行编译来验证,例如:

$ CGO_ENABLED=0 go build -o ./app ./app-folder

该命令可能会失败,因此您的选择可能会:

  1. 重构依赖cgo来使用本机go替代项的go代码部分,或者...
  2. 在具有兼容ABI作为执行目标平台的计算机上进行编译。

另请参阅Application binary interface (ABI)GCC ABI Compatibility