doucuodan0897 2015-04-27 16:58
浏览 81
已采纳

Go Lang:如何在Windows上安装libxml2 / gokogiri

If there a relatively simple way to make go + libxml2 + gokogiri work on windows?

I mean that I may be can install it (but at the moment I can not, stuck with Package libxml-2.0 was not found in the pkg-config search path), but then I need to provide my utilite to other people, who will never be able (or would wish ) to install lall libxml2 dependencies, modify PATH etc on windows...

It work flawless on Ubuntu...

I found this https://github.com/moovweb/gokogiri/issues/49 thats funny with installation of Gimp 2 (what?!), but I still cannot make it run with such error, I guess might be issue with PATH, but all PATH are set

$ go get github.com/moovweb/gokogiri
# github.com/moovweb/gokogiri/help
Documents\go\src\github.com\moovweb\gokogiri\help\help.go:6:25: fatal error: lib
xml/tree.h: No such file or directory
 #include <libxml/tree.h>
                         ^
compilation terminated.
# github.com/moovweb/gokogiri/xpath
Documents\go\src\github.com\moovweb\gokogiri\xpath\expression.go:4:26: fatal err
or: libxml/xpath.h: No such file or directory
 #include <libxml/xpath.h>
                          ^
compilation terminated.
  • 写回答

2条回答 默认 最新

  • doushun1870 2015-06-21 17:47
    关注

    You are struggling because it is hard to combine packages that were built by different people for different purposes and get your environment set up correctly. I think it is best to use MSYS2, an environment for Windows that provides a consistent set of packages for things like gcc, go, libxml2, and iconv. MSYS2 has a package manager (pacman) that helps you easily install them and keep them updated.

    I don't do much programming with Go, but I am familiar with MSYS2 and it seems like I was able to get gokogiri installed using MSYS2. You should open MSYS2's "MinGW-w64 Win64 Shell" from the Start menu (mingw64_shell.bat), and try running these commands:

    pacman -S mingw-w64-x86_64-{gcc,go,libxml2,iconv}
    export GOROOT=/mingw64/
    export GOPATH=/c/Users/David/Documents/goproj/
    mkdir -p $GOPATH
    go git github.com/moovweb/gokogiri
    

    I think GOPATH should be set to the directory of your project. If you run into an error, it might be because some pacman package is required that I didn't list here.

    The string mingw-w64-x86_64-{gcc,go,libxml2,iconv} gets expanded by Bash into the following list of packages:

    mingw-w64-x86_64-gcc
    mingw-w64-x86_64-go
    mingw-w64-x86_64-libxml2
    mingw-w64-x86_64-iconv
    

    If you are actually using 32-bit Windows, replace x86_64 with i686 in the instructions above.

    If you are curious, the scripts for building those packages are here: https://github.com/Alexpux/MINGW-packages

    As a disclaimer, I haven't actually compiled any go programs in MSYS2, so there could be big problems I am unaware of.

    Also, one of the main developers of MSYS2 (alexpux) said this in the #msys2 IRC chat on 2015-06-21:

    We not build go for a long time. This package in very WIP state Also see https://github.com/Alexpux/MINGW-packages/issues/421

    So you might need to fix some issues with the MSYS2 Go package and recompile it yourself to really make this work. But you have the PKGBUILD script that was used to build it, so maybe that will be less hard than what you are trying to do right now, which involves compiling/collecting every dependency of gokogiri.

    MSYS2 would make your other installation of go, libxml2, and iconv obsolete. You can delete those things once you get your MSYS2 environment working.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3