从lua 4.0.1升级到5.1.4时出现链接错误。

我正在处理一份非常古老的源代码(在Red Hat中编译)。之前它使用的是lua-4.0.1,所以我编译了最新的lua(lua-5.1.4)并将其安装在与旧版本相同的目录下。实现不是很大,所以除了改一下函数名称并包含“lauxlib.h”以便编译之外,没什么需要改动的了。它可以编译,但是会出现以下链接错误。

/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标志已经存在了。

我想知道可以尝试的方法。任何帮助都很感激。这让我发疯了。

原文链接 https://stackoverflow.com/questions/6922912

点赞
stackoverflow用户311635
stackoverflow用户311635

在线性命令的末尾加入-ldl。顺序很重要。

链接器仅在命令行上排名更靠右的库中搜索未引用符号的库。你的新liblua.a现在使用dlopen等函数,而旧版不支持。因为-ldl-llua的左侧,所以链接器不使用libdl来链接lua引用。

2011-08-03 07:17:58