V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
q569321245
V2EX  ›  程序员

golang plugin mac 平台下交叉编译 生成 .so 文件 报错

  •  
  •   q569321245 · Apr 15, 2021 · 1546 views
    This topic created in 1851 days ago, the information mentioned may be changed or developed.
    命令:
    CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -buildmode=plugin -o=./release.so main.go
    
    结果:
    # command-line-arguments
    /usr/local/go/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
    ld: unknown option: -z
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    
    在谷歌上没找到对应的解决方案
    
    
    Supplement 1  ·  Apr 15, 2021
    ```
    CGO 的交叉编译,CGO_ENABLED 必须开启 需要辅助编译器实现交叉编译
    mac 系统安装如下的辅助编译器:
    brew install FiloSottile/musl-cross/musl-cross
    window 系统安装如下:
    brew install mingw-w64

    执行:
    CGO_ENABLED=1 GOOS=linux GOARCH=amd64 CC=/usr/local/bin/x86_64-linux-musl-gcc go build -buildmode=plugin -o=release.so main.go

    结果:
    /lib64/libc.so: invalid ELF header
    ```
    1 replies    2021-04-15 18:41:40 +08:00
    warlock
        1
    warlock  
       Apr 15, 2021
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1654 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 16:21 · PVG 00:21 · LAX 09:21 · JFK 12:21
    ♥ Do have faith in what you're doing.