【发布时间】:2014-07-31 12:33:46
【问题描述】:
更新
在项目 2(console) 中使用 -ldl 和链接 liblua.a 后,编译没问题,但是当它运行时,一旦运行 Lua 函数,它就会因错误 Segment fault (core dumped) 而崩溃。
问题背景:
-
操作系统:Linux Ubuntu
-
IDE:代码块
-
语言:C++
-
2个项目:
-
项目1:使用Lua的静态库;
-
项目2:控制台应用,使用项目1生成的lib
-
问题描述
项目 1(静态库)构建成功。
问题是在构建项目2时,它说项目1的lib中的那些Lua函数是未定义的,这是错误消息的一部分:
g++ -o bin/Release/BattleConsoleCB obj/Release/main.o -s
../BattleConsole/libBattleCore.a
../BattleConsole/libBattleCore.a(DataLoader.o):
In function `boolDataLoader::GetNumber<double>(char const*, double&) [clone .isra.5]':
DataLoader.cpp:(.text+0x13): undefined reference to `lua_settop'
DataLoader.cpp:(.text+0x1e): undefined reference to `lua_getglobal'
DataLoader.cpp:(.text+0x2b): undefined reference to `lua_isnumber'
DataLoader.cpp:(.text+0x3e): undefined reference to `lua_tonumberx'
DataLoader.cpp:(.text+0x51): undefined reference to `lua_settop'
请注意,“DataLoader.cpp”来自项目 1,它应该已经构建在应该嵌入 Lua 的静态库“libBattleCore.a”中。
如何解决问题?感谢您的帮助。
附加信息:
-
项目 2 应包括:“libBattleCore.h”、“main.cpp”、libBattleCore.a
-
项目 1:CodeBlockbuilding 选项已在编译搜索目录中包含“Lua/install/include”,在链接搜索目录中包含“Lua/install/lib”
-
同样的代码用VS2012成功构建并在Win上运行
-
如果还有什么需要的,请告知,我会补充的。
-
我是 linux 和 g++ 的新手。 :-(
谢谢
【问题讨论】:
-
可能你需要指定 -l 参数给 g++ 来告诉你需要重新链接 lua 库。代码块应该有这个配置。
-
那该怎么办?我已经尝试在项目 2 中包含 lua/include 和 lua/lib,但仍然出现相同的错误。鉴于此,我如何将 lua 嵌入到库中?
-
在VS2012的“Project Properties\Configuration Management\Linker\Additional Libraries”中搜索,可能有来自lua的.lib,如果有,需要同样配置CodeBlock,意思是明确指定搜索那个 .lib
-
kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32。 lib;odbccp32.lib;%(AdditionalDependencies) 没有 lua...
-
您可能应该尝试使用
-llua5.1或您正在使用的lua 版本。这添加到代码块中的链接器命令行。
标签: c++ linux lua static-libraries