Reputation: 43427
Problem:
$ clang++ -L../lib/osx/ -I../include/ -o test Script.cpp Main.cpp Verbose.cpp -llua -lUnitTest++
Undefined symbols for architecture x86_64:
"_lua_pcall", referenced from:
LuaSystem::dostring(char const*) in Script-EgY0dM.o
(maybe you meant: _lua_pcallk)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Let's look at my lua build:
$ cd src/
stevenlu443@steven-mba(Jun 09 02:41:58)[~/Downloads/lua-5.2.0/src]
$ ls
Makefile lcorolib.c ldump.o llex.o lopcodes.o ltable.c luac.c
lapi.c lcorolib.o lfunc.c llimits.h loslib.c ltable.h luac.o
lapi.h lctype.c lfunc.h lmathlib.c loslib.o ltable.o luaconf.h
lapi.o lctype.h lfunc.o lmathlib.o lparser.c ltablib.c lualib.h
lauxlib.c lctype.o lgc.c lmem.c lparser.h ltablib.o lundump.c
lauxlib.h ldblib.c lgc.h lmem.h lparser.o ltm.c lundump.h
lauxlib.o ldblib.o lgc.o lmem.o lstate.c ltm.h lundump.o
lbaselib.c ldebug.c liblua.a loadlib.c lstate.h ltm.o lvm.c
lbaselib.o ldebug.h linit.c loadlib.o lstate.o lua lvm.h
lbitlib.c ldebug.o linit.o lobject.c lstring.c lua.c lvm.o
lbitlib.o ldo.c liolib.c lobject.h lstring.h lua.h lzio.c
lcode.c ldo.h liolib.o lobject.o lstring.o lua.hpp lzio.h
lcode.h ldo.o llex.c lopcodes.c lstrlib.c lua.o lzio.o
lcode.o ldump.c llex.h lopcodes.h lstrlib.o luac
stevenlu443@steven-mba(Jun 09 02:41:59)[~/Downloads/lua-5.2.0/src]
$ nm liblua.a | grep _lua_pcall
115:0000000000001a30 T _lua_pcallk
116:0000000000003b40 S _lua_pcallk.eh
1563: U _lua_pcallk
1839: U _lua_pcallk
stevenlu443@steven-mba(Jun 09 02:42:12)[~/Downloads/lua-5.2.0/src]
$ nm *.o | grep _lua_pcall
115:0000000000001a30 T _lua_pcallk
116:0000000000003b40 S _lua_pcallk.eh
597: U _lua_pcallk
977: U _lua_pcallk
2630: U _lua_pcallk
2760: U _lua_pcallk
Why does _lua_pcall
not exist? The 5.2 doc seems to say pcallk does the same as pcall but has the benefit of being able to yield but pcall should still be available...
UPDATE: I just realized I am trying to link to 5.2 using older (5.1?) headers... Does anybody know where there is a list that says which headers are necessary? I don't need all the headers from the Lua source.
We can infer from what we've seen here that in 5.2 pcall is implemented using _lua_pcallk
.
Upvotes: 2
Views: 1565
Reputation: 72312
To compile programs that use the Lua C API, you need to include lua.h
and frequently also lauxlib.h
and sometimes lualib.h
.
When you change the version of Lua, say from 5.1 to 5.2, you need to recompile your program. When you change releases of the same version, say from 5.1.4 to 5.1.5, you don't need to recompile, just relink.
Of course, in all cases, make sure you use consistent headers and libraries, that is, do not mix headers and libraries from different versions or releases.
Upvotes: 4