Lua linker problems - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Programming Languages & Scripting (/forum-8.html)
+--- Thread: Lua linker problems (/thread-8190.html)
Lua linker problems - ripburger - Oct 10, 2010 12:31 PM
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:
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.
RE: Lua linker problems - OneSadCookie - Oct 10, 2010 03:23 PM
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.
RE: Lua linker problems - ripburger - Oct 10, 2010 06:29 PM
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.
RE: Lua linker problems - ajrs84 - Apr 24, 2012 11:56 AM
(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.
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?
RE: Lua linker problems - OneSadCookie - Apr 24, 2012 01:30 PM
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.
RE: Lua linker problems - ajrs84 - Apr 24, 2012 02:49 PM
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?
RE: Lua linker problems - OneSadCookie - Apr 24, 2012 04:16 PM
By looking at how the makefile works.