本地mac打包golang二进制文件到linux服务器报错:
-bash: ./atmp-linux: No such file or directory
很奇怪,明明可执行文件在当前目录下,为什么会找不到呢? 使用列出动态库依赖的lld(list dynamic dependencies)命令查看了下,发现:
ldd atmp-linux
发现报错:
./atmp-linux: error while loading shared libraries: /lib64/libc.so: invalid ELF header
执行file看看:
file atmp-linux
atmp-linux: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-musl-x86_64.so.1, with debug_info, not stripped
于是检查mac下的打包脚本,发现打包脚本不对:
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 CC=x86_64-linux-musl-gcc CXX=x86_64-linux-musl-g++ go build -o atmp-linux main.go
改成了就解决了问题:
GOOS=linux GOARCH=amd64 go build -o atmp-linux main.go
执行file看看:
标签:x86,No,atmp,golang,报错,file,linux,go,64 From: https://blog.51cto.com/thinklili/9218966atmp-linux: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, with debug_info, not stripped