一、cgo项目调用dll文件一直显示
Failed to load xxxxx.dll: The specified module could not be found.
二、项目目录结构大致如下
cashop
cgodemo
include
cgodemo.h
lib
xxxx.so
xxxx.so.4.5
go.mod
cgodemo_linux.go
cgodemo_windows.go
router
model
template
widows_dist
config.yaml
xxxx.dll
xxxxxxx.dll
xxxxx.dll
go.mod
go.sum
main.go
三、go.mod文件 replace本地库
module xxx
go 1.14
require (
cashop/cgodemo v1.0.0
github.com/gin-gonic/gin v1.7.7
...
)
replace cashop/cgodemo v1.0.0 => ./cgodemo
四、goland执行报错
Failed to load xxxxx.dll: The specified module could not be found.
五、修改goland工作以及输出目录,重新编译,解决问题
分析原因
在cgodemo cgodemo_windows.go中调用了了windows_dist文件夹下的xxxx.dll文件
因为没有设置默认工作目录导致实际执行再根目录,设置工作目录为windows_dist可以查找到对应的dll文件了