Lua linker problems

Nibbie
Posts: 2
Joined: 2010.10
Post: #1
I'm attempting to add Lua scripting to a C project in Xcode. I've added the Lua header file directory in the path, and my #includes compile fine, but I get linker errors, for ppc and i386:

Code:
_lua_pcall
_luaL_newstate
_luaL_loadfile
_luaopen_io
_lua_setfield
_luaopen_math
_luaopen_string
_luaopen_loadlib
_lua_pushcclosure
_luaopen_table
_luaopen_base

all referenced from SDL_main in main.o, which is the Cocoa wrapper for my SDL program.

I'm really lost as to what's going wrong, and every tutorial or forum I can find isn't specific enough to know what I'm missing.

Thanks in advance.

[EDIT]: Just to be clearer - I understand that the header files allow my program to compile, and that the linker error results from the linker trying to put the actual function definitions in with my code, I just don't know how to get the definitions to the linker.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
You need to build lua, and add liblua.a to your project, or (probably easier) just add the lua source files to your project.

Note if you choose the latter option that at least one of the lua source files is for the standalone interpreter, which will cause "multiple definitions of _main" if you add it, so exercise a little caution.
Quote this message in a reply
Nibbie
Posts: 2
Joined: 2010.10
Post: #3
Ok thanks, OSC. Now I need to figure out how to get Xcode to not target ppc architecture. I changed the project settings and the active target settings to "i386" instead of "ppc i386" but still get errors for ppc.

[EDIT]: Decided to just include source files, so ppc links fine too. Would be nice to know how to turn it off though.
Quote this message in a reply
Apprentice
Posts: 15
Joined: 2012.03
Post: #4
(Oct 10, 2010 03:23 PM)OneSadCookie Wrote:  You need to build lua, and add liblua.a to your project, or (probably easier) just add the lua source files to your project.

Note if you choose the latter option that at least one of the lua source files is for the standalone interpreter, which will cause "multiple definitions of _main" if you add it, so exercise a little caution.

I ran into the duplicate symbols issue while trying to do exactly this. I commented out the 2 main() functions and the thing compiles fine and seems to work. So my question is to onesadcookie, is this this safe? And what did you mean by exercise a little caution?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #5
The right way to do this will still to be to build lua on the command-line with make, and add the liblua.a to your project. I understand that that's not necessarily trivial to do, though, particularly if you want a multiarchitecture or iOS build.

If you want to add the source files to your project, you should only include those that belong to liblua, not those that belong to the interpreter. You should not have to edit any lua source, and I'd be wary of doing so. At best you'll end up compiling a bunch of code that's never called.
Quote this message in a reply
Apprentice
Posts: 15
Joined: 2012.03
Post: #6
Originally I had intended to build the lib.a file via the command line (which I did do for my projects macosx target), however, after opening up the makefile and not seeing a iOS or arm anywhere I got nervous. Then I proceeded to poke around google for about an hour and still found nothing worthwhile. I can't believe there's not a binary floating around the Internet somewhere.

Also, how would you differentiate between files belonging to liblua and files belonging to the interpreter?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #7
By looking at how the makefile works.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Linker in Xcode ia3n_g 7 4,294 Jul 22, 2006 02:46 PM
Last Post: ia3n_g