当安装了libiconv环境下安装lua-iconv 会出现报错 /usr/local/lib/lua/5.1/iconv.so: undefined symb

转自: http://bbs.iresty.com/topic/25/%E5%BD%93%E5%AE%89%E8%A3%85%E4%BA%86libiconv%E7%8E%AF%E5%A2%83%E4%B8%8B%E5%AE%89%E8%A3%85lua-iconv-%E4%BC%9A%E5%87%BA%E7%8E%B0%E6%8A%A5%E9%94%99-usr-local-lib-lua-5-1-iconv-so-undefined-symbol-libiconv
当安装了libiconv环境下安装lua-iconv 会出现报错 /usr/local/lib/lua/5.1/iconv.so: undefined symbol: libiconv
王 王海波 29天之前
当libiconv先安装的时候会出现报错
/usr/local/lib/lua/5.1/iconv.so: undefined symbol: libiconv
stack traceback:
[C]: at 0x0044dfb0
[C]: in function 'require'
stdin:1: in main chunk
[C]: at 0x004045d0

简单的处理方式:
mv /usr/local/include/iconv.h ~/
luarocks install lua-iconv后再恢复

过程:
参考
http://www.cnblogs.com/lightsong/p/4634642.html
https://github.com/ittner/lua-iconv/issues/3
https://groups.google.com/forum/#!msg/openresty/blNGlzAl2ik/QuJBXtzLx9gJ

经过查证(受到此文启发 http://tonybai.com/2013/04/25/a-libiconv-linkage-problem/),

分析为先安装了 libiconv库, 导致 此库的iconv.h拷贝到 usr/local/include/iconv.h

然后编译 luaiconv工程,编译文件iconv.c文件时候, gcc先找到 usr/local/include/iconv.h 此文件, 以此文件内部的函数声明为准,编译出iconv.so

实际上次应该以系统提供的 iconv.h 为准, 此文件在 /usr/include/iconv.h

头文件gcc搜索次序:

:~/share_windows/openSource/lua/lua-iconv-lua-iconv-5$ ld -verbose | grep SEARCH
SEARCH_DIR("=/usr/i686-linux-gnu/lib32"); SEARCH_DIR("=/usr/local/lib32"); SEARCH_DIR("=/lib32"); SEARCH_DIR("=/usr/lib32"); SEARCH_DIR("=/usr/i686-linux-gnu/lib"); SEARCH_DIR("=/usr/local/lib/i386-linux-gnu"); SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/lib/i386-linux-gnu"); SEARCH_DIR("=/lib"); SEARCH_DIR("=/usr/lib/i386-linux-gnu"); SEARCH_DIR("=/usr/lib");

libiconv-------usr/local/include/iconv.h

#ifndef LIBICONV_PLUG
#define iconv_open libiconv_open
#endif
extern LIBICONV_DLL_EXPORTED iconv_t iconv_open (const char* tocode, const char* fromcode);

libiconv -- iconv.c 中 libiconv_open 定义收到宏控制, 应该未开启, 或者编译 luaiconv未链接libiconv库

#if defined FreeBSD && !defined gnu_freebsd
/* GNU libiconv is the native FreeBSD iconv implementation since 2002.
It wants to define the symbols 'iconv_open', 'iconv', 'iconv_close'. */
#define strong_alias(name, aliasname) _strong_alias(name, aliasname)
#define _strong_alias(name, aliasname)
extern __typeof (name) aliasname attribute ((alias (#name)));
#undef iconv_open
#undef iconv
#undef iconv_close
strong_alias (libiconv_open, iconv_open)
strong_alias (libiconv, iconv)
strong_alias (libiconv_close, iconv_close)
#endif

解决方法: 修改实现文件中, 引用的 iconv.h 引用方式, 将标准方式, 修改为自定义,并且写为全路径 /usr/include/iconv.h

然后再次 make && make install, 运行ok

vim luaiconv.c

#include <lua.h>
#include <lauxlib.h>
#include <stdlib.h>

#include "/usr/include/iconv.h"
#include <errno.h>

你可能感兴趣的:(当安装了libiconv环境下安装lua-iconv 会出现报错 /usr/local/lib/lua/5.1/iconv.so: undefined symb)