github.com/lestrrat-go/libxml2 这个xpath包在windows下无法使用

报错信息:
 
(base) PS C:\git\qiniu_web_gin> go run .\main.go
# github.com/lestrrat-go/libxml2/xpath
C:\Users\xda\go\pkg\mod\github.com\lestrrat-go\libxml2@v0.0.0-20201123224832-e6d9de61b80d\xpath\xpath.go:40:35: undefined: clib.XMLXPathObjectType
C:\Users\xda\go\pkg\mod\github.com\lestrrat-go\libxml2@v0.0.0-20201123224832-e6d9de61b80d\xpath\xpath.go:45:14: undefined: clib.XMLXPathObjectFloat64
C:\Users\xda\go\pkg\mod\github.com\lestrrat-go\libxml2@v0.0.0-20201123224832-e6d9de61b80d\xpath\xpath.go:50:14: undefined: clib.XMLXPathObjectBool
C:\Users\xda\go\pkg\mod\github.com\lestrrat-go\libxml2@v0.0.0-20201123224832-e6d9de61b80d\xpath\xpath.go:74:18: undefined: clib.XMLXPathObjectNodeList
C:\Users\xda\go\pkg\mod\github.com\lestrrat-go\libxml2@v0.0.0-20201123224832-e6d9de61b80d\xpath\xpath.go:91:18: undefined: clib.XMLXPathObjectNodeList
C:\Users\xda\go\pkg\mod\github.com\lestrrat-go\libxml2@v0.0.0-20201123224832-e6d9de61b80d\xpath\xpath.go:124:7: undefined: clib.XMLXPathFreeObject
C:\Users\xda\go\pkg\mod\github.com\lestrrat-go\libxml2@v0.0.0-20201123224832-e6d9de61b80d\xpath\xpath.go:129:19: undefined: clib.XMLXPathCompile
C:\Users\xda\go\pkg\mod\github.com\lestrrat-go\libxml2@v0.0.0-20201123224832-e6d9de61b80d\xpath\xpath.go:149:7: undefined: clib.XMLXPathFreeCompExpr
C:\Users\xda\go\pkg\mod\github.com\lestrrat-go\libxml2@v0.0.0-20201123224832-e6d9de61b80d\xpath\xpath.go:163:22: undefined: clib.XMLXPathNewContext
C:\Users\xda\go\pkg\mod\github.com\lestrrat-go\libxml2@v0.0.0-20201123224832-e6d9de61b80d\xpath\xpath.go:179:14: undefined: clib.XMLXPathContextSetContextNode
C:\Users\xda\go\pkg\mod\github.com\lestrrat-go\libxml2@v0.0.0-20201123224832-e6d9de61b80d\xpath\xpath.go:179:14: too many errors
(base) PS C:\git\qiniu_web_gin> go get github.com/lestrrat-go/libxml2
(base) PS C:\git\qiniu_web_gin>

然后到作者的官网上逛了一圈,出现这个问题,需要自己编译一个libxml2 windows版本的
 
官方给出的是源码:
libxml2-2.11.5-win-build Latest
Corresponding to official release version 2.11.5.


3476aaa157ac45f4a3ae4da04274b536.png

 

8599f7480474440b8273abb5a58aa41f.png

 
然后编译C的源码,需要很多的工具链和依赖。
windows至少需要Visual Studio, 不是vs code呢。 Visual Studio安装完,至少要被占用10GB的空间。
 

213ce11b6a0443e8b49b9787d6ac1320.png

 
libxml2 + iconv + msvc 在windows下生成使用库
为了跨平台的解析xml,偶然获得Linux下比较好用的一个xml的解析库libxml2,使用起来确实比较简单,方便;但移植到windows下后发下使用上存在问题:
无法解析格式位GB2312类型的XML文件,但由于一些外部因素,Windows下必须使用GB2312格式
在网上查看了诸多教程,有很多编译生成libxml2库的文章,但都不支持iconv,仔细阅读README后,终于生成了可用的libxml2.lib库,记录下来备用

操作系统:windows 7 x64
版本:libiconv-1.15, libxml2 Github版本
Visual Studio版本:vs2015
Cygwin:x64

以下操作皆为生成x64位库,32位的基本类似,可以查看具体的README。

 
所以想想还是算了,直接切换到ubuntu开发了。惹不起,还躲不起吗 :(
 
我:@lestrrat Hi, is that mean it can't work on windows if i dont build it with visual studio or cgywin like?

作者:It's the same as when you are building a C program. You build in the same arch/os as the where you intend to run the program.

我:Thanks a lot. Instsall vs environment taks lots of time, so i switch to the ubuntu to "quick fix this issue" :(

逃-》
 
 

0 个评论

要回复文章请先登录注册