webp icon indicating copy to clipboard operation
webp copied to clipboard

Mac下编译不了linux的binary?

Open FTwOoO opened this issue 5 years ago • 3 comments

$ CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build ./main.go

# command-line-arguments /usr/local/go/pkg/tool/darwin_amd64/link: running clang failed: exit status 1 ld: warning: ignoring file /var/folders/m2/nwyl7pg57j378_k7qqfghmpw0000gn/T/go-link-956317668/go.o, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 ) Undefined symbols for architecture x86_64: "__cgo_topofstack", referenced from: __cgo_26061493d47f_C2func_getnameinfo in 000002.o __cgo_26061493d47f_Cfunc_getnameinfo in 000002.o __cgo_26061493d47f_C2func_getaddrinfo in 000004.o __cgo_26061493d47f_Cfunc_gai_strerror in 000004.o __cgo_26061493d47f_Cfunc_getaddrinfo in 000004.o __cgo_9b69751600cf_Cfunc_WebPGetFeatures in 000018.o __cgo_9b69751600cf_Cfunc_webpDecodeGray in 000018.o ... "_main", referenced from: implicit entry/start for main executable ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

FTwOoO avatar Jun 11 '20 08:06 FTwOoO

I can confirm I run into this as well:

prologic@Jamess-iMac
Mon Aug 31 09:33:03
~/Projects/jointwt/twtxt
 (master) 2
$ CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build ./cmd/twtd/...
# github.com/prologic/twtxt/cmd/twtd
/usr/local/Cellar/go/1.14.6/libexec/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
ld: warning: ignoring file /var/folders/8h/c9gl4gms3fjb0kyf7nb42ybh0000gn/T/go-link-693526846/go.o, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x7F 0x45 0x4C 0x46 0x02 0x01 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 )
Undefined symbols for architecture x86_64:
  "__cgo_topofstack", referenced from:
      __cgo_26061493d47f_C2func_getnameinfo in 000002.o
      __cgo_26061493d47f_Cfunc_getnameinfo in 000002.o
      __cgo_26061493d47f_C2func_getaddrinfo in 000004.o
      __cgo_26061493d47f_Cfunc_gai_strerror in 000004.o
      __cgo_26061493d47f_Cfunc_getaddrinfo in 000004.o
      __cgo_9b69751600cf_Cfunc_WebPGetFeatures in 000006.o
      __cgo_9b69751600cf_Cfunc_webpDecodeGray in 000006.o
      ...
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

prologic avatar Aug 30 '20 23:08 prologic

Build your code in linux, it could be more easy.

yuhang2 avatar Aug 31 '20 09:08 yuhang2

Build your code in linux, it could be more easy.

That really defeats the point of cross-compiilation :) I primarily to dev on an Mac. I could do the release from Linux via Github Workflow actions and runner I suppose. Is there no way we can fix this in this codebase?

prologic avatar Sep 01 '20 05:09 prologic