【问题标题】:CGO build go file with cygwin and opensslCGO 使用 cygwin 和 openssl 构建 go 文件
【发布时间】:2021-11-12 23:04:12
【问题描述】:

我正在尝试编译一些包含一些 C 的 go 代码并使用 openssl 库。我是一个窗口,我使用 cygwin64 作为 gcc 编译器和 openssl 开发库。但是,当我运行命令时,出现以下错误:

/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: could not find -lmingwex
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: could not find -lmingw32

但是,当我在 cygwin 中查看时,我找不到 lmingw32 或 lmingwex。有什么想法吗?

【问题讨论】:

    标签: go gcc openssl cgo


    【解决方案1】:

    ziglang/zig issue 7874 所示,我将首先测试是否可以使用ziglang 从 git bash(使用 msys2,没有 Cygwin)编译相同的 Go/C 代码

    CGO_ENABLED=1 GOOS=windows GOARCH=amd64 CC="zcc" CXX="zc++" go build main.go
    

    与,在%PATH%

    zcc
    
    #!/bin/sh
    zig cc -target x86_64-windows-gnu $@
    
    zc++
    
    #!/bin/sh
    zig c++ -target x86_64-windows-gnu $@
    

    你也可以关注“Using Zig on Windows with msys2 toolchain

    OP Thomas 中的the comments 报告:

    我使用了以下命令:

    CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build main.go

    ,它起作用了;)

    【讨论】:

    • 然后使用 $PATH,而不是 %PATH%
    • 我不明白 PATH 的东西......你可以为一个假人解释它吗?
    • @Thomas 您的脚本(或我在答案中提到的脚本)必须位于 Windows %PATH% 的文件夹之一中(也用于您的 cygwin $PATH):superuser.com/a/155687/141 (一般路径:computerhope.com/issues/ch000549.htm
    • 我使用了以下命令:CGO_ENABLED=1 GOOS=windows GOARCH=amd64 go build main.go,它成功了;)谢谢你的帮助,没有你就做不到
    • @Thomas 干得好。我已将您的评论包含在答案中以提高知名度。
    猜你喜欢
    • 2020-11-12
    • 2018-08-10
    • 1970-01-01
    • 2017-11-05
    • 2018-12-28
    • 1970-01-01
    • 2019-07-23
    • 2021-11-20
    • 1970-01-01
    相关资源
    最近更新 更多