- cgo-libevent-for-windows
- 参考文章:
- 1.环境(windows)
- 2.下载libevent源码 并制作dll动态库 利用mingw-utils生成.a .def
- 3.测试代码:
- 4.go build:
https://www.kancloud.cn/idzqj/customer/2026575
https://www.cnblogs.com/pandamohist/p/14227440.html
安装文件和具体文档都在setup文件夹中
go 1.13 libevent 2.1.10 cmake 3.22 mingw && mingw-utils visualstudio 2013/2017 openssl2.下载libevent源码 并制作dll动态库 利用mingw-utils生成.a .def
根据libevent编译手册 *** 作即可
mingw-utils命令:
pexports libevent.dll > libevent.def dlltool.exe -D libevent.dll -d libevent.def -l libevent.a -k pexports libevent_core.dll > libevent_core.def dlltool.exe -D libevent_core.dll -d libevent_core.def -l libevent_core.a -k pexports libevent_extra.dll > libevent_extra.def dlltool.exe -D libevent_extra.dll -d libevent_extra.def -l libevent_extra.a -k3.测试代码:
package main import "C" import ( "fmt" "unsafe" ) func main() { C.puts(C.CString("cgo-libevent-for-windows")) var pev *C.struct_event = C.getEventPtr() var ptv *C.struct_timeval = C.getTvPtr() var base *C.struct_event_base base = C.event_base_new() //*C.struct_event_base var pbase *C.struct_event_base = (*C.struct_event_base)(unsafe.Pointer(base)) C.ev_set_timer(pev, (C.cb)(unsafe.Pointer(C.timer_cb))) C.event_base_set(pbase, pev) C.event_add(pev, ptv) C.event_base_dispatch(pbase) C.event_base_free(pbase) Pause() } func Pause() { var str string fmt.Println("") fmt.Print("请按任意键继续...") fmt.Scanln(&str) fmt.Print("程序退出...") }4.go build:
常见错误:cgo_libevent_for_windows cc1.exe: sorry, unimplemented: 64-bit mode not compiled in
windows命令行: SET CGO_ENABLED=1 SET GOOS=windows SET GOARCH=386 SET GO111MODULE=off go build -x goland编译器: goland-environment:CGO_ENABLED=1;GOOS=windows;GOARCH=3865.github地址:
https://github.com/zld126126/cgo_libevent_for_windows
6.效果欢迎分享,转载请注明来源:内存溢出
评论列表(0条)