iconv-go升级过程中的编译问题

binbinjx · · 2234 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。

 

工作项目原因,需要对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);
}

*/

我了个去,darwinfreebsd,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);
}

*/

再进行编译。奇迹般的通过了,通过了,通过了。。。

好吧,目前只是这样猥琐的解决的。这样写不知道会不会对跨平台造成影响。先这样解决吧。记录一下。

如果哪位同仁看到这篇文章,觉得不是这样解决的,请不吝赐教。

 


有疑问加站长微信联系(非本文作者)

本文来自:博客园

感谢作者:binbinjx

查看原文:iconv-go升级过程中的编译问题

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

2234 次点击  ∙  1 赞  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传