Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

链接LuaJIT-2.0.2的静态库报错,需要在./bundle/ngx_lua-0.9.2/config中加入-ldl参数 #40

Closed
cf2012 opened this issue Dec 19, 2013 · 6 comments

Comments

@cf2012
Copy link

cf2012 commented Dec 19, 2013

程序版本: ngx_openresty-1.4.3.4
操作系统: Ubuntu 12.04.1 LTS
编译器版本: gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
Luajit版本: LuaJIT-2.0.2

编译时, 我想用静态库: libluajit-5.1.a
所以将 $LuaJIT_HOME/lib 下的_.so_全删了.

然后执行:
./configure --prefix=pwd --with-luajit=/opt/LuaJIT-2.0.2

报错:
./configure: error: ngx_http_lua_module requires the Lua or LuaJIT library and LUAJIT_LIB is defined as /opt/LuaJIT-2.0.2/lib and LUAJIT_INC (path for lua.h) /opt/LuaJIT-2.0.2/include/luajit-2.0, but we cannot find LuaJIT there.

在bundle/nginx-1.4.3/auto/feature的47行之后添加:
cat $NGX_AUTOTEST.c
echo "/bin/sh -c "$ngx_test" >> $NGX_AUTOCONF_ERR 2>&1"

调试发现真正的报错信息为:
/opt/LuaJIT-2.0.2/lib/libluajit-5.1.a(lj_clib.o): In function clib_getsym': /run/shm/ngx_openresty-1.4.3.4/build/LuaJIT-2.0.2/src/lj_clib.c:140: undefined reference to dlsym'
/opt/LuaJIT-2.0.2/lib/libluajit-5.1.a(lj_clib.o): In function clib_loadlib': /run/shm/ngx_openresty-1.4.3.4/build/LuaJIT-2.0.2/src/lj_clib.c:117: undefined reference to dlopen'

LuaJIT-2.0.2/lib/pkgconfig/luajit.pc 中:
Requires:
Libs: -L${libdir} -l${libname}
Libs.private: -Wl,-E -lm -ldl

链接阶段用静态库的话, 需要在gcc加 -ldl 参数..

修改./bundle/ngx_lua-0.9.2/config, 添加 -ldl 参数后编译成功. :-)

@agentzh
Copy link
Member

agentzh commented Dec 19, 2013

You don't need to edit ngx_lua's config file for this. You can just pass the --with-ld-opt="-ldl" to nginx or openresty's ./configure script.

BTW, this place is supposed to be English only. If you really want to use Chinese, please join the openresty (Chinese) mailing list and post there instead:

https://groups.google.com/group/openresty

Thank you for your cooperation!

@cf2012
Copy link
Author

cf2012 commented Dec 19, 2013

I passed the `--with-ld-opt="-ldl" to openresty's ./configure and got the same error.

$ tail -20 ngx_openresty-1.4.3.4/build/nginx-1.4.3/objs/autoconf.err

/run/shm/ngx_openresty-1.4.3.4/build/LuaJIT-2.0.2/src/lj_clib.c:125: undefined reference to `dlerror'
/dev/shm/LuaJIT-2.0.2/lib/libluajit-5.1.a(lj_clib.o): In function `clib_unloadlib':
/run/shm/ngx_openresty-1.4.3.4/build/LuaJIT-2.0.2/src/lj_clib.c:135: undefined reference to `dlclose'
/dev/shm/LuaJIT-2.0.2/lib/libluajit-5.1.a(lj_clib.o): In function `clib_error_':
/run/shm/ngx_openresty-1.4.3.4/build/LuaJIT-2.0.2/src/lj_clib.c:37: undefined reference to `dlerror'
collect2: ld returned 1 exit status
----------

#include <sys/types.h>
#include <unistd.h>
#include <lauxlib.h>

int main() {
    (void) luaL_newstate();;
    return 0;
}

----------
cc -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 \
-I /opt/LuaJIT-2.0.2/include/luajit-2.0 \
-o objs/autotest objs/autotest.c \
-Wl,-rpath,/opt/LuaJIT-2.0.2/lib \
-ldl -L/opt/LuaJIT-2.0.2/lib -lluajit-5.1 -lm
----------

I put "-ldl" to the end of line .
cc -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -I /opt/LuaJIT-2.0.2/include/luajit-2.0
-o objs/autotest objs/autotest.c
-Wl,-rpath,/opt/LuaJIT-2.0.2/lib -L/opt/LuaJIT-2.0.2/lib -lluajit-5.1 -lm -ldl

and it works.

@agentzh
Copy link
Member

agentzh commented Dec 19, 2013

Oh right. the order matters. I'll look into this. Thanks for the feedback.

agentzh added a commit to openresty/lua-nginx-module that referenced this issue Jul 9, 2014
@agentzh
Copy link
Member

agentzh commented Jul 9, 2014

@cf2012 Just committed a fix to the git master branch of ngx_lua. Thank you for the report and sorry for the delay on my side!

@agentzh agentzh closed this as completed Jul 9, 2014
@jlynet
Copy link

jlynet commented Jan 5, 2018

@cf2012 能帮看一下这个问题吗?
checking for LuaJIT library in /usr/local/lib and /usr/local/include/luajit-2.0 (win32) ...
#include <sys/types.h>

#include <lauxlib.h>

int main(void) {
#if LUA_VERSION_NUM != 501

error unsupported Lua language version

#endif
(void) luaL_newstate();;
return 0;
}

/bin/sh -c cl -I/usr/local/include/luajit-2.0 -W3 -DFD_SETSIZE=1024 -I /usr/local/include/luajit-2.0 -o objs/autotest objs/autotest.c -L/usr/local/lib -L/usr/local/lib -llua51 >> objs/autoconf.err 2>&1
not found
./auto/configure: error: ngx_http_lua_module requires the Lua or LuaJIT library and LUAJIT_LIB is defined as /usr/local/lib and LUAJIT_INC (path for lua.h) /usr/local/include/luajit-2.0, but we cannot find LuaJIT there.

@agentzh
Copy link
Member

agentzh commented Jan 5, 2018

@ai930 Please, no Chinese here. This place is considered English only. If you really
want to use Chinese, please join the openresty (Chinese) mailing list instead.
Please see https://openresty.org/en/community.html Thanks for your cooperation.

Also, please do not hijack and comment on unrelated github issues, especially this closed one. This is rude.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants