[英]lua loads my c++ shared library but not its dependent shared libraries
我有一個c ++(舊版)應用程序,該應用程序需要一些lua腳本來實現某些功能。
現在,我正在編寫一個新的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++
我沒有提到任何lua5.1這樣的鏈接文件。
但是此power.so在運行時需要lua-5.1.so。
現在,我有一個C ++舊版應用程序,其中已編譯了lua52。
並調用alert.lua進行一些工作。
package.cpath = package.cpath .. ";/usr/lib64/power.so"
package.cpath = package.cpath .. ";/usr/lib64/liblua-5.1.so"
require("power")
注意:負載功率的lua在lua5.2上運行
Power.so編譯並取決於lua5.1
我得到一個錯誤
undefined symbol: lua_setfield'
這些版本是否必須相同?
有人可以闡明這個問題嗎?
編輯:如果我用lua52.so編譯power.so,那么lua腳本和C ++應用程序異常終止。
如果在構建power.so時不提及-llua52,則在運行時會出現錯誤,提示未定義符號。
編輯:更多說明:
有一個C ++應用程序.exe。 (samplecpp)還有一個與lua 5.2庫一起構建的.dll / .sh,因此具有lua以及其他功能。 (luaplugin.so)
該luaplugin.so可以調用已配置的任何lua腳本。 它調用並執行lua腳本中的函數。
現在我有一個lua腳本,我想將其連接到其他c ++模塊。
我正在寫的C ++模塊(構建為.so依賴lua52.so)依次使用lua函數進行注冊等。因為必須從lua腳本中加載它。
但是在運行時,samplecpp執行lua腳本並且luascript需要c ++ .so時,在c ++ .so中使用的lua函數上出現了無法解決的錯誤。
如何使它引用samplecpp本身可用的lua函數?
是的,您需要使用為相同版本的Lua編譯的C / C ++庫。
Lua的不同版本之間沒有ABI兼容性。
參見http://www.lua.org/versions.html#numbering
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.