dongxie3352 2018-03-02 22:44
浏览 204

使用Golang 1.10无法编译Windows DLL

I'm having issues building a Windows DLL in Golang 1.10, which is supported in this latest version:

"The various build modes have been ported to more systems. Specifically, c-shared now works on linux/ppc64le, windows/386, and windows/amd64;" (Source: https://golang.org/doc/go1.10)

I have a very simple program right now (main.go) that only exports one function "Test", but am having issues when using the following "go build" command: env GOOS=windows GOARCH=386 go build -buildmode=c-shared main.go

Specifically, receiving the can't load package: package main: build constraints exclude all Go files in [PATH] error. The source code for main.go is shown below:

package main

import (
    "C"
    "fmt"
)

func main() {
    fmt.Println("from main")
}

//export Test
func Test() string {
    return "this is a test"
}

I've never encountered this error before and building without specifying GOOS and GOARCH works. Hoping someone has encountered this issue and can help me out.

  • 写回答

1条回答 默认 最新

  • douzhi3776 2018-03-02 23:42
    关注
    1. Make sure you have MinGW installed on Ubuntu: sudo apt-get install gcc-mingw-w64-i686 and sudo apt-get install gcc-mingw-w64-x86-64

    2. Compile using the following commands: env GOOS=windows GOARCH=386 CGO_ENABLED=1 CC=i686-w64-mingw32-gcc go build -buildmode=c-shared -o main.dll main.go and env GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc go build -buildmode=c-shared -o main.dll main.go

    3. Verify generated DLL works by testing the "Test" export: rundll32.exe main.dll,Test

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题