[英]lua loads my c++ shared library but not its dependent shared libraries
I have a c++ (legacy) application which calls some lua scripts for some functionality. 我有一个c ++(旧版)应用程序,该应用程序需要一些lua脚本来实现某些功能。
Now i am writing a new c++ library which should be called from that lua script. 现在,我正在编写一个新的c ++库,应该从该lua脚本中调用它。
#include <lua.hpp>
extern "C" {
static int isquare(lua_State *L){ /* Internal name of func */
return 1; /* One return value */
}
static int icube(lua_State *L){ /* Internal name of func */
return 1; /* One return value */
}
/* Register this file's functions with the
* luaopen_libraryname() function, where libraryname
* is the name of the compiled .so output. In other words
* it's the filename (but not extension) after the -o
* in the cc command.
*
* So for instance, if your cc command has -o power.so then
* this function would be called luaopen_power().
*
* This function should contain lua_register() commands for
* each function you want available from Lua.
*
*/
int luaopen_power(lua_State *L){
printf("before power open");
lua_register(
L, /* Lua state variable */
"square", /* func name as known in Lua */
isquare /* func name in this file */
);
lua_register(L,"cube",icube);
printf("after power register");
return 0;
}
}
g++ -Wall -shared -fPIC -o power.so -I/usr/include/lua5.1 hellofunc.cpp -lstdc++
I did not mention any lua5.1 so file for linking. 我没有提到任何lua5.1这样的链接文件。
but this power.so needs lua-5.1.so at runtime. 但是此power.so在运行时需要lua-5.1.so。
Now, i have a C++ legacy application which has lua52 compiled within it. 现在,我有一个C ++旧版应用程序,其中已编译了lua52。
And it calls alert.lua for some work. 并调用alert.lua进行一些工作。
package.cpath = package.cpath .. ";/usr/lib64/power.so"
package.cpath = package.cpath .. ";/usr/lib64/liblua-5.1.so"
require("power")
Note: the lua which loads the power.so runs on lua5.2 注意:负载功率的lua在lua5.2上运行
Power.so is compiled and depends on lua5.1 Power.so编译并取决于lua5.1
And i get an error 我得到一个错误
undefined symbol: lua_setfield'
Does these versions have to be same ? 这些版本是否必须相同?
Can someone shed some light on this issue? 有人可以阐明这个问题吗?
EDIT: If i compile power.so with lua52.so then the lua script and the C++ application aborts unusually . 编辑:如果我用lua52.so编译power.so,那么lua脚本和C ++应用程序异常终止。
If if dont mention -llua52 while building power.so then at runtime there is an error saying undefined symbol. 如果在构建power.so时不提及-llua52,则在运行时会出现错误,提示未定义符号。
EDIT: More Explanation: 编辑:更多说明:
There is a C++ application .exe. 有一个C ++应用程序.exe。 (samplecpp) There is also a .dll/.sh which is built along with the lua 5.2 library hence having lua as well as other functionality. (samplecpp)还有一个与lua 5.2库一起构建的.dll / .sh,因此具有lua以及其他功能。 (luaplugin.so) (luaplugin.so)
This luaplugin.so can call any lua script which is configured. 该luaplugin.so可以调用已配置的任何lua脚本。 It calls and executes functions in lua script. 它调用并执行lua脚本中的函数。
Now i have a lua script which i want to conenct to a different c++ module. 现在我有一个lua脚本,我想将其连接到其他c ++模块。
The c++ module(build to .so having dependency on lua52.so) i am writing in turn uses lua functions for registration etc. As it has to be loaded from the lua script. 我正在写的C ++模块(构建为.so依赖lua52.so)依次使用lua函数进行注册等。因为必须从lua脚本中加载它。
But at runtime when samplecpp executes the lua script and when luascript requires the c++ .so, im getting unresolved error on the lua functions that are used in the c++ .so. 但是在运行时,samplecpp执行lua脚本并且luascript需要c ++ .so时,在c ++ .so中使用的lua函数上出现了无法解决的错误。
How can i make it refer the lua functions that are available in the samplecpp itself ? 如何使它引用samplecpp本身可用的lua函数?
Yes, you need to use C/C++ libraries compiled for the same version of Lua. 是的,您需要使用为相同版本的Lua编译的C / C ++库。
There is no ABI compatibility between different versions of Lua. Lua的不同版本之间没有ABI兼容性。
See http://www.lua.org/versions.html#numbering 参见http://www.lua.org/versions.html#numbering
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.