hi there,
由于某些原因不能直接使用openresty,只好单独手动把lua-ngx编译到nginx中。由于luajit2.0已经稳定,所以尝试给数台centos的机器的ngx_lua升级到luajit版本。
但是升级过程中遇到了以下现象:configure的时候报错
checking for LuaJIT library in /usr/local/lib and /usr/local/include/luajit-2.0 (specified by the LUAJIT_LIB and LUAJIT_INC env) ... not found
./configure: error: the ngx_lua addon requires the lua or luajit library and LUAJIT_LIB is defined as /usr/local/lib and LUAJIT_INC /usr/local/include/luajit-2.0, but we cannot find LuaJIT there.
看上去是因为 LUAJIT_LIB LUAJIT_INC 两个环境变量指定有误造成的问题,但是实际上这两个文件夹是正确的。
机器条件和相关软件版本:
OS:centos 5.4
ngx源码版本 1.0.15
ngx_lua 源码版本 最新git版本
lua版本 5.1 安装路径/usr/local
luajit版本,2.0.0 stable 安装路径 /usr/local
/usr/local/lib下存在以下lua开头的文件
liblua.a
libluajit-5.1.a
libluajit-5.1.so.2 -> libluajit-5.1.so.2.0.0
libluajit-5.1.so.2.0.0
/usr/local/include/luajit-2.0目录下存在以下文件
lauxlib.h
luaconf.h
lua.h
lua.hpp
luajit.h
lualib.h
LUAJIT_LIB=/usr/local/lib
LUAJIT_INC=/usr/local/include/luajit-2.0
出问题的命令行:./configure --prefix=/usr/local/nginx --with-http_sub_module --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --add-module=../agentzh-echo-nginx-module --add-module=../chaoslawful-lua-nginx-module --add-module=../simpl-ngx_devel_kit
(以上module目录均存在)
分析过程:
由于我判断LUAJIT_LIB / INC 路径是没有给错的,所以我直接看了下 objs/autoconf.err 文件,有价值的信息如下:
----------------------------------------
checking for LuaJIT library in /usr/local/lib and /usr/local/include/luajit-2.0 (specified by the LUAJIT_LIB and LUAJIT_INC env)
/usr/local/lib/libluajit-5.1.a(lj_clib.o): In function `lj_clib_unload':
lj_clib.c:(.text+0x9d): undefined reference to `dlclose'
/usr/local/lib/libluajit-5.1.a(lj_clib.o): In function `clib_error_':
lj_clib.c:(.text+0xb5): undefined reference to `dlerror'
/usr/local/lib/libluajit-5.1.a(lj_clib.o): In function `lj_clib_load':
lj_clib.c:(.text+0x1bf): undefined reference to `dlopen'
lj_clib.c:(.text+0x214): undefined reference to `dlerror'
lj_clib.c:(.text+0x2ec): undefined reference to `dlopen'
lj_clib.c:(.text+0x2fd): undefined reference to `dlerror'
/usr/local/lib/libluajit-5.1.a(lj_clib.o): In function `lj_clib_index':
lj_clib.c:(.text+0x47e): undefined reference to `dlsym'
collect2: ld 返回 1
----------
#include <sys/types.h>
#include <unistd.h>
#include <lauxlib.h>
int main() {
(void) luaL_newstate();;
return 0;
}
----------
gcc -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -I /usr/local/include/luajit-2.0 -o objs/autotest objs/autotest.c -L/usr/local/lib -lluajit-5.1 -lm
----------
目测问题出在编译自动测试文件上:
gcc -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -I /usr/local/include/luajit-2.0 -o objs/autotest objs/autotest.c -L/usr/local/lib -lluajit-5.1 -lm
执行这行命令行时ld出错了,手工加载ld的一切正常。
gcc -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -I /usr/local/include/luajit-2.0 -o objs/autotest objs/autotest.c -L/usr/local/lib -lluajit-5.1 -lm -ldl
之后一切顺利。
疑问:
为什么会出现autotest失效的问题,是因为我的configure命令参数有问题还是有某种bug的存在?
除了修改ngx_lua模块的config文件以外,我还能怎样修复这个问题?
其实是一个小问题,但是怕描述不清楚情况,所以说的比较啰嗦,还请各位读者见谅,帮我看看这个问题 :P
谢谢!