英文:
How can I install a go package with MinGW which depends on libiconv
问题
我目前正在尝试设置一个Go项目,考虑到我正在使用Windows,而另外两个开发者正在使用Mac,我在安装一些包时遇到了一些问题。
在使用cmd安装包后,我只能成功安装其中的两个,其他两个需要gcc。
因此,我安装了MinGW。通过这种方式,我成功安装了第三个包,但现在我在https://github.com/mikkyang/id3-go上遇到了困难。
它似乎依赖于另一个底层项目https://github.com/djimenez/iconv-go。每当我尝试go install
id3-go时,都会出现以下错误:
src\github.com\djimenez\iconv-go\converter.go:8:19: fatal error: iconv.h: No such file or directory
我需要在MinGW中使用libiconv,但我不知道如何连接这两部分。我对这个领域并不是很了解,所以非常感谢任何帮助。我已经下载了Windows版的libiconv。
我在github项目中找到了相关问题的附加信息:
https://github.com/mikkyang/id3-go/issues/21
编辑:我在整个问题上取得了一些进展。我现在已经获得了所有需要的文件,但现在我遇到了以下警告:
# github.com/djimenez/iconv-go
E:/Tools/TDM-GCC/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -liconv
collect2.exe: error: ld returned 1 exit status
我尝试将libiconv安装中的libiconv2.a添加到mingw32 lib文件夹中,但结果如下:
# github.com/djimenez/iconv-go
E:/Tools/TDM-GCC/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible E:/Tools/TDM-GCC/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libiconv.a when searching for -liconv
E:/Tools/TDM-GCC/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible E:/Tools/TDM-GCC/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/lib/../lib\libiconv.a when searching for -liconv
E:/Tools/TDM-GCC/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible E:/Tools/TDM-GCC/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/lib/libiconv.a when searching for -liconv
E:/Tools/TDM-GCC/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible E:/Tools/TDM-GCC/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/lib\libiconv.a when searching for -liconv
E:/Tools/TDM-GCC/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible E:/Tools/TDM-GCC/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libiconv.a when searching for -liconv
E:/Tools/TDM-GCC/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible E:/Tools/TDM-GCC/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/lib/libiconv.a when searching for -liconv
E:/Tools/TDM-GCC/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -liconv
collect2.exe: error: ld returned 1 exit status
我不知道如何继续下一步。
英文:
I am currently trying to set up a Go project, and considering I am running Windows, while the other 2 developers are working on a Mac, I have some trouble with installing a few packages.
After trying to install the packages with cmd, I was only able to install 2 out of 4. The other two needed gcc.
Therefore, I installed MinGW. I was able to install a third package that way, but now I am stuck on https://github.com/mikkyang/id3-go.
It seems to depend on another underlying project, https://github.com/djimenez/iconv-go. The moment I try to go install
id3-go, I am always left with this error:
src\github.com\djimenez\iconv-go\converter.go:8:19: fatal error: iconv.h: No such file or directory
Somehow, I need to use libiconv with MinGW, but I have no idea how to connect both parts. I'm not really an expert in that field, so any help would be appreciated a lot. I already downloaded libiconv for Windows.
Related issue for additional information I found on the github project:
https://github.com/mikkyang/id3-go/issues/21
EDIT: I made some progress on the whole problem. I now got all the files I need, but now I am stuck with this warning:
# github.com/djimenez/iconv-go
E:/Tools/TDM-GCC/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -liconv
collect2.exe: error: ld returned 1 exit status
I tried to add the libiconv2.a from my libiconv installation to the mingw32 lib folder, but then this is what I end up with:
# github.com/djimenez/iconv-go
E:/Tools/TDM-GCC/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible E:/Tools/TDM-GCC/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libiconv.a when searching for -liconv
E:/Tools/TDM-GCC/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible E:/Tools/TDM-GCC/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/lib/../lib\libiconv.a when searching for -liconv
E:/Tools/TDM-GCC/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible E:/Tools/TDM-GCC/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/lib/libiconv.a when searching for -liconv
E:/Tools/TDM-GCC/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible E:/Tools/TDM-GCC/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/lib\libiconv.a when searching for -liconv
E:/Tools/TDM-GCC/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible E:/Tools/TDM-GCC/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/lib/../lib/libiconv.a when searching for -liconv
E:/Tools/TDM-GCC/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible E:/Tools/TDM-GCC/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/lib/libiconv.a when searching for -liconv
E:/Tools/TDM-GCC/bin/../lib/gcc/x86_64-w64-mingw32/5.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -liconv
collect2.exe: error: ld returned 1 exit status
I have no idea how to proceed from here.
答案1
得分: 3
我在想要go install github.com/google/gopacket
时遇到了同样的问题,它需要CGO
。这是因为你的libiconv2.a
是由其他编译器生成的,所以与mingw32编译器不兼容,正如错误消息所说。我们需要使用mingw32工具集生成静态库:
-
在你的电脑上找到libiconv-2.dll(对应的动态库)。
-
在这些文件上运行
gendef
(在我的64位Windows中位于C:\TDM-GCC-64\x86_64-w64-mingw32\bin),命令为gendef libiconv-2.dll
,这将生成libiconv2.def文件。 -
然后生成静态库:
dlltool --as-flags=--64 -m i386:x86-64 -k --output-lib libiconv2.a --input-def libiconv2.def
-
将libiconv2.a复制到适当的位置。
英文:
I've met the same problem when I want to go install github.com/google/gopacket
which need CGO
. It's because your libiconv2.a
is generated by other compiler, so it's incompatible with mingw32 compiler as the error message says. We need generate the static lib with the mingw32 toolset:
-
find libiconv-2.dll(the coresonding dynamic library) in your PC
-
run
gendef
(located in C:\TDM-GCC-64\x86_64-w64-mingw32\bin in my 64-bit Windows ) on those filesgendef libiconv-2.dll
, this will generate libiconv2.def file -
Then generate the static library:
dlltool --as-flags=--64 -m i386:x86-64 -k --output-lib libiconv2.a --input-def libiconv2.def
-
copy libiconv2.a to proper location.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论