Reputation: 265
I'm trying to write some C++ functions that can be run from Lua. However, when I try to import the header files, I get the following error:
Undefined symbols for architecture x86_64:
"_luaL_loadfilex", referenced from:
_main in main.o
"_luaL_newstate", referenced from:
_main in main.o
"_luaL_openlibs", referenced from:
_main in main.o
"_lua_close", referenced from:
_main in main.o
"_lua_pcallk", referenced from:
_main in main.o
"_lua_pushcclosure", referenced from:
_main in main.o
"_lua_setglobal", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I've already added the file path to the Header Search Paths option in the Build Settings.
Here is the import code:
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
What am I doing wrong?
Upvotes: 2
Views: 1441
Reputation: 10015
For a first working version, get the library here, extract the header files and the .a
file into the same directory as the project file which has the code you posted in your question, then try to compile and link normally.
You may keep the references locally as in your question:
extern "C" {
#include "lua.h"
#include "lualib.h"
#include "lauxlib.h"
}
Later you refine your environment if that is needed.
Upvotes: 1
Reputation: 29493
The error you are getting is a link error not a compile error. The linker (called "ld") is complaining that it can't resolve symbols related to Lua. Make sure you have -llua52 in your link command so your library links to the Lua shared library (might be -llua or -llua5.2 on your system), and tell the linker where to find that lib via -Lpath/to/Lua/lib/folder.
Upvotes: 1