工作项目原因,需要对golang进行升级。升级之后老的iconv-go运行有问题。因为新的golang运行更加严格,所以需要升级iconv-go.
从djimenez/iconv-go 拉下来代码进行编译发现“找不到iconv库的一些接口”,目测是库没链进来。错误信息如下:
go install ./... # github.com/djimenez/iconv-go /tmp/go-build579267556/github.com/djimenez/iconv-go/_obj/converter.cgo2.o: In function `_cgo_5f3e10abf205_Cfunc_iconv_open‘: src/github.com/djimenez/iconv-go/converter.go:142: undefined reference to `libiconv_open‘ /tmp/go-build579267556/github.com/djimenez/iconv-go/_obj/converter.cgo2.o: In function `_cgo_5f3e10abf205_Cfunc_iconv_close‘: src/github.com/djimenez/iconv-go/converter.go:128: undefined reference to `libiconv_close‘ /tmp/go-build579267556/github.com/djimenez/iconv-go/_obj/converter.cgo2.o: In function `_cgo_5f3e10abf205_C2func_iconv_open‘: src/github.com/djimenez/iconv-go/converter.go:87: undefined reference to `libiconv_open‘ /tmp/go-build579267556/github.com/djimenez/iconv-go/_obj/converter.cgo2.o: In function `_cgo_5f3e10abf205_C2func_iconv_close‘: src/github.com/djimenez/iconv-go/converter.go:71: undefined reference to `libiconv_close‘ /tmp/go-build579267556/github.com/djimenez/iconv-go/_obj/converter.cgo2.o: In function `call_iconv‘: src/github.com/djimenez/iconv-go/converter.go:13: undefined reference to `libiconv‘ collect2: ld returned 1 exit status
很奇怪,本地明明有安装iconv,怎么就找不到iconv库?
iconv --version iconv (GNU libiconv 1.14) Copyright (C) 2000-2011 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Written by Bruno Haible.
进到iconv-go的converter.go发现
package iconv /* #cgo darwin LDFLAGS: -liconv #cgo freebsd LDFLAGS: -liconv #cgo windows LDFLAGS: -liconv #include <stdlib.h> #include <iconv.h> // As of GO 1.6 passing a pointer to Go pointer, will lead to panic // Therofore we use this wrapper function, to avoid passing **char directly from go size_t call_iconv(iconv_t ctx, char *in, size_t *size_in, char *out, size_t *size_out){ return iconv(ctx, &in, size_in, &out, size_out); } */
我了个去,darwin,freebsd,windows都有。但是我在centos下使用的。难不成是这个原因,导致iconv库没有链进去?于是尝试进行了修改。
package iconv /* #cgo darwin LDFLAGS: -liconv #cgo freebsd LDFLAGS: -liconv #cgo windows LDFLAGS: -liconv #cgo LDFLAGS: -liconv #include <stdlib.h> #include <iconv.h> // As of GO 1.6 passing a pointer to Go pointer, will lead to panic // Therofore we use this wrapper function, to avoid passing **char directly from go size_t call_iconv(iconv_t ctx, char *in, size_t *size_in, char *out, size_t *size_out){ return iconv(ctx, &in, size_in, &out, size_out); } */
再进行编译。奇迹般的通过了,通过了,通过了。。。
好吧,目前只是这样猥琐的解决的。这样写不知道会不会对跨平台造成影响。先这样解决吧。记录一下。
如果哪位同仁看到这篇文章,觉得不是这样解决的,请不吝赐教。
时间: 2024-11-08 06:09:17