andelf / go-curl

golang curl(libcurl) binding.
Apache License 2.0
485 stars 131 forks source link

I don't know how to install curl in Windows(不知道怎么装curl 在windows) #49

Closed wz2cool closed 8 years ago

wz2cool commented 8 years ago

HI, I'm new for golang/c. When I run example, it will throw an exception "..\callback.go:6:23: fatal error: curl/curl.h: No such file or directory". I know I need to install curl but I don't know how to do that. Could you give me more detail to fix this.

我不知道怎么装curl, 能给写详细点么怎么装curl

wz2cool commented 8 years ago

I use Windows platform to develop not linux. so my problem is how to install curl in Windows and use it in golang

andelf commented 8 years ago

首先你需要一个MingW/gcc环境,保证你的cgo可以正常工作。 我找到了一份教程 http://itekblog.com/windows-go/#Installingmingw

然后在 curl 页面下载curl的开发binary https://curl.haxx.se/download.html Win64 - MinGW64 一栏。放到MingW对应目录,lib include

wz2cool commented 8 years ago

大哥谢谢 好像没那个错了 但是开始报其他错,我这个curl 版本比你那个高,我找不到你那个7.22 版本的不知道是不是对应不上,我是小白 C:\Users\Frank\AppData\Local\Temp\go-build560987318\github.com\andelf\go-curl_obj\core.cgo2.o: In function cgo_1aa5c582df5b_Cfunc_curl_getdate': E:/workspace/git/go/src/github.com/andelf/go-curl/core.go:47: undefined reference to_imp__curl_getdate'

andelf commented 8 years ago

这个是链接错误,一般是找不到lib导致的,你看看你的对应lib文件在不再

wz2cool commented 8 years ago

大神 我终于折腾好了 我说一下咋弄的,你帮忙看看

  1. 我先去自己编译了一下 libcurl , 参考http://blog.mcxiaoke.com/2010/12/12/compile-and-use-libcurl-in-mingw-win32-how-to/
  2. 我修改了源码,添加了两行 在 core.go 中

    cgo CFLAGS: -I. -Ic:/curllib/include -g -O2 -DCURL_STATICLIB -c

    cgo LDFLAGS: -Lc:/curllib/lib -lcurl -lwldap32 -lws2_32

  3. 遇到了已经存在的问题,解决方法是注释掉, 参考 https://github.com/andelf/go-curl/issues/30
  4. 我发现运行examples 中的 simple.go 还是报错 我发现是其他example 导致的, 于是我删除了其他例子只保留 simple.go

终于编译成功了。。。。

andelf commented 8 years ago

@wz2cool 现在看起来有点问题就是 win32不能支持 multi.go 。手头没环境不能整。。