2011-08-03 54 views
3

我正在研究一个非常旧的源代码(在Red Hat中编译)。在它有lua-4.0.1之前,我只编译了最新的lua(lua-5.1.4),并将它安装在与旧版本相同的目录中。这个实现并不是很大,除了几个函数名称之外,没有太多的改变,我不得不包含“lauxlib.h”来编译它。它编译没有任何问题,但它给出了这些链接错误。从lua 4.0.1升级到5.1.4时出现链接错误

/usr/local/lib/liblua.a(loadlib.o): In function `ll_load': 
loadlib.o(.text+0x19): undefined reference to `dlopen' 
loadlib.o(.text+0x2a): undefined reference to `dlerror' 
/usr/local/lib/liblua.a(loadlib.o): In function `ll_sym': 
loadlib.o(.text+0x52): undefined reference to `dlsym' 
loadlib.o(.text+0x63): undefined reference to `dlerror' 
/usr/local/lib/liblua.a(loadlib.o): In function `ll_unloadlib': 
loadlib.o(.text+0x8): undefined reference to `dlclose' 

基本上所有的路径是正确的,但我用的是相同的标志编译器与旧,我还没有改变makefile文件在所有。

-static -lpthread -lnsl -lutil -ldl -lmysqlclient -llua -llualib -lz -lcppunit 

ldl标志已经存在。

我只想知道要尝试的东西。一切都被赞赏。这让我疯狂。

回答

5

-ldl放在班轮命令的末尾。顺序很重要。

链接器仅在站点更靠右的命令行中的库中搜索履行未引用符号的库。你的新liblua.a现在使用dlopen和朋友,而旧的没有。由于-ldl保留为-llua,因此链接器不使用libdl来链接lua引用。

相关问题