V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
q569321245
V2EX  ›  程序员

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

  •  
  •   q569321245 · 2021-04-15 18:33:00 +08:00 · 1086 次点击
    这是一个创建于 1100 天前的主题,其中的信息可能已经有所发展或是发生改变。
    命令:
    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)
    
    在谷歌上没找到对应的解决方案
    
    
    第 1 条附言  ·  2021-04-15 20:01:13 +08:00
    ```
    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 条回复    2021-04-15 18:41:40 +08:00
    warlock
        1
    warlock  
       2021-04-15 18:41:40 +08:00
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   981 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 22:41 · PVG 06:41 · LAX 15:41 · JFK 18:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.