1
的Mac OS complie的Dynamic C LIB誤差(LIB功能將在LUA調用)的Mac OS complie的Dynamic C LIB誤差(LIB功能將在LUA調用)
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
#include <stdio.h>
static int myCfunc (lua_State *L)
{
printf ("Roses are Red\n");
return 0;
}
int luaopen_fromlua(lua_State *L)
{
static const luaL_Reg Map[] = { {"dothis", myCfunc}, {NULL,NULL} } ;
luaL_register(L, "cstuff", Map);
return 1;
}
編譯錯誤1:
william:Desktop william$ gcc -o example.so -I /usr/local/include -L /usr/local/lib -fpic -shared test.c -llua -Wall
test.c: In function ‘main’:
test.c:43: warning: implicit declaration of function ‘lua_open’
test.c:43: warning: assignment makes pointer from integer without a cast
Undefined symbols for architecture x86_64:
"_lua_open", referenced from:
_main in cczPGNkR.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
william:Desktop william$
編譯錯誤2:
william:Desktop william$ g++ -o example.so -L/usr/local/lib -I/usr/local/include test.c -llualib
test.c: In function ‘int luaopen_fromlua(lua_State*)’:
test.c:18: error: ‘luaL_register’ was not declared in this scope
william:Desktop william$
我的環境:
Mac 10.7.5
william:Desktop william$ lua -v
Lua 5.2.2 Copyright (C) 1994-2013 Lua.org, PUC-Rio
william:Desktop william$
william:Desktop william$ locate lua
/usr/local/Library/Formula/lua.rb
/usr/local/Library/Formula/luajit.rb
/usr/local/Library/Formula/luarocks.rb
/usr/local/Library/Formula/metalua.rb
/usr/local/bin/lua
/usr/local/bin/luac
/usr/local/include/lua.h
/usr/local/include/lua.hpp
/usr/local/include/luaconf.h
/usr/local/include/lualib.h
/usr/local/lib/liblua.a
/usr/local/lib/lua
/usr/local/lib/lua/5.2
/usr/local/man/man1/lua.1
/usr/local/man/man1/luac.1
/usr/local/share/lua
/usr/local/share/lua/5.2
/usr/share/file/magic/lua
有些身體可以幫我解決嗎? 感謝
動態庫在Mac上擴展名爲.dylib而不是ELF/* NIX .so。 – Will 2013-04-10 10:35:20
此外,這個問題可能會爲您提供一些有用的信息:http://stackoverflow.com/q/1212477/1353098 – Will 2013-04-10 10:36:59