Go lang: how to install libxml2/gokogiri on windows

huangapple go评论93阅读模式
英文:

Go lang: how to install libxml2/gokogiri on windows

问题

在Windows上,有一种相对简单的方法可以使go + libxml2 + gokogiri工作吗?

我的意思是,我可能可以安装它(但目前我无法安装,卡在Package libxml-2.0 was not found in the pkg-config search path),但是我需要将我的工具提供给其他人,他们将永远无法(或者不愿意)在Windows上安装所有libxml2的依赖项,修改PATH等等...

在Ubuntu上它可以无缝运行...

我找到了这个链接https://github.com/moovweb/gokogiri/issues/49,关于Gimp 2的安装(什么?!),但是我仍然无法解决这个错误,我猜可能是PATH的问题,但是所有的PATH都已经设置好了。

$ 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.
英文:

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.

答案1

得分: 2

你正在努力解决一个问题,即如何将由不同人为不同目的构建的软件包组合起来,并正确设置你的环境。我认为最好使用MSYS2,这是一个为Windows提供一致软件包集的环境,包括gcc、go、libxml2和iconv。MSYS2有一个包管理器(pacman),可以帮助你轻松安装和更新它们。

我不常用Go进行编程,但我熟悉MSYS2,并且似乎我能够使用MSYS2成功安装gokogiri。你应该从开始菜单中打开MSYS2的"MinGW-w64 Win64 Shell"(mingw64_shell.bat),然后尝试运行以下命令:

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

我认为GOPATH应该设置为你的项目目录。如果遇到错误,可能是因为我没有在这里列出所需的某个pacman软件包。

字符串mingw-w64-x86_64-{gcc,go,libxml2,iconv}会被Bash扩展为以下软件包列表:

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

如果你实际上使用的是32位Windows,请在上述指令中将x86_64替换为i686

如果你感兴趣,构建这些软件包的脚本在这里:https://github.com/Alexpux/MINGW-packages

作为免责声明,我实际上没有在MSYS2中编译过任何go程序,所以可能存在我不知道的大问题。

此外,MSYS2的主要开发者之一(alexpux)在2015-06-21的#msys2 IRC聊天中说过:

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

所以你可能需要修复一些MSYS2 Go软件包的问题,并自己重新编译它,以确保它能正常工作。但是你有用于构建它的PKGBUILD脚本,所以也许比你现在尝试做的事情要容易一些,因为那涉及到编译/收集gokogiri的每个依赖项。

一旦你的MSYS2环境正常工作,你可以删除你的其他go、libxml2和iconv安装。

英文:

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 get 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.

答案2

得分: 0

如果您正在使用Visual Studio并且想要向您的项目添加依赖项,那么只需使用NuGet包管理器进行安装,这是最简单的方法。
安装命令:Install-Package libxml2

英文:

If you are using visual studio and want to add dependency to your project then just install it using NuGet Package Manager it's easiest method.
Install command: Install-Package libxml2

huangapple
  • 本文由 发表于 2015年4月28日 00:58:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/29901728.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定