Lua liblua5.1.so无法打开共享对象文件
所以我有一个 .so 格式的已编译 C 文件,并尝试在 Lua 中使用它。这两个文件的代码是:
-- luatest.lua:
require("power")
print("Enter a number: ")
local num = tonumber(io.read())
local n = create(num)
square(n)
cube(n)
nprint(n)
// luatest.c compiled to power.so
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#include <stdlib.h>
static int createStruct(lua_State *L);
static int isquare(lua_State *L);
static int icube(lua_State *L);
static int nprint(lua_State *L);
typedef struct numbers {
float number;
float square;
float cube;
} numbers;
int luaopen_power(lua_State *L){
lua_register(L, "create", createStruct);
lua_register(L, "square", isquare);
lua_register(L,"cube",icube);
lua_register(L, "nprint", nprint);
return 0;
}
static int createStruct(lua_State *L){
// Code here
}
static int isquare(lua_State *L){
// Code here
}
static int icube(lua_State *L){
// Code here
}
static int nprint(lua_State *L){
// Code here
}
C 代码编译良好。但是当我尝试这样做时:
cd <directory>
lua luatest.lua
我收到以下错误:
lua: error loading module 'power' from file './power.so':
liblua5.1.so: cannot open shared object file: No such file or directory
stack traceback:
[C]: ?
[C]: in function 'require'
luatest.lua:3: in main chunk
[C]: ?
我不确定出了什么问题,因为 ./power.so 应该存在。
我在 openSUSE 64 位上遇到此错误,但这个确切的代码在 OSX 上运行良好。
任何对此的见解都会很棒,我似乎在任何地方都找不到其他人遇到这个问题。
So I have a compiled C file in .so format, and am trying to use it from within Lua. The code for the 2 files is:
-- luatest.lua:
require("power")
print("Enter a number: ")
local num = tonumber(io.read())
local n = create(num)
square(n)
cube(n)
nprint(n)
// luatest.c compiled to power.so
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#include <stdlib.h>
static int createStruct(lua_State *L);
static int isquare(lua_State *L);
static int icube(lua_State *L);
static int nprint(lua_State *L);
typedef struct numbers {
float number;
float square;
float cube;
} numbers;
int luaopen_power(lua_State *L){
lua_register(L, "create", createStruct);
lua_register(L, "square", isquare);
lua_register(L,"cube",icube);
lua_register(L, "nprint", nprint);
return 0;
}
static int createStruct(lua_State *L){
// Code here
}
static int isquare(lua_State *L){
// Code here
}
static int icube(lua_State *L){
// Code here
}
static int nprint(lua_State *L){
// Code here
}
The C code compiles fine. But when I try to do:
cd <directory>
lua luatest.lua
I get the following error:
lua: error loading module 'power' from file './power.so':
liblua5.1.so: cannot open shared object file: No such file or directory
stack traceback:
[C]: ?
[C]: in function 'require'
luatest.lua:3: in main chunk
[C]: ?
I'm not sure what's wrong as ./power.so should exist.
I'm getting this error on openSUSE 64bit, but this exact code works fine on OSX.
Any insight into this would be great, I can't seem to find anyone else with this issue anywhere.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)