|
| 23 Oct 2011 11:09 PM |
// This is C, by the way. I also had to take of the html tag thingies. #include stdio.h #include lua.h #include lauxlib.h #include lualib.h int main (void) { lua_State *L; L = lua_open(); return 0; }
How does that simple code not run with my computer? I get the error:
Undefined symbols for architecture x86_64: "_luaL_newstate", referenced from: _main in cc3s8w3w.o ld: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status
I would ask in Scripting Helpers, but I doubt that most of them know what C is.
|
|
|
| Report Abuse |
|
|
GoldenUrg
|
  |
| Joined: 23 Aug 2009 |
| Total Posts: 6428 |
|
|
| 23 Oct 2011 11:19 PM |
Did you link in the actual Lua code?
|
|
|
| Report Abuse |
|
|
|
| 23 Oct 2011 11:22 PM |
| I don't think so (I've never tried linking Lua with C before). I don't think there is any Lua code. Where would I put it, anyway? In another file in the same directory? |
|
|
| Report Abuse |
|
|
XlegoX
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 14955 |
|
|
| 24 Oct 2011 12:20 AM |
| You need to tell the linker to include the actual Lua library, not just include the header in your code. All headers do in C is tell the linker and your source files that a certain function is being used... you still have to include the libraries to tell the linker where to find the implementation of those functions. |
|
|
| Report Abuse |
|
|
|
| 24 Oct 2011 06:45 PM |
| How do I do that? Sadly, I'm not very knowledgeable with the stuff underlying C. Would I do this with C code or in the Terminal, etc? |
|
|
| Report Abuse |
|
|
XlegoX
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 14955 |
|
|
| 24 Oct 2011 06:56 PM |
| You don't do it in the source file itself. You have to add the command to include the library by adding an extra thing onto the command line you use to compile it, or by using adding it to the IDE's list of libraries to include, so that the IDE knows to add it to the command line for you. |
|
|
| Report Abuse |
|
|
|
| 24 Oct 2011 06:59 PM |
| Okay. Which library should I include then? |
|
|
| Report Abuse |
|
|
|
| 24 Oct 2011 07:12 PM |
Well, I compiled with
gcc -m32 -o output32
and got the error
Undefined symbols for architecture i386: "_luaL_newstate", referenced from: _main in cc7rfYWL.o ld: symbol(s) not found for architecture i386`
which means the same thing. What sort of extra thing would I add to the command line, anyway? |
|
|
| Report Abuse |
|
|
|
| 24 Oct 2011 07:14 PM |
You ARE including the lua dlls, right?
~+[Y U NO WORSHIP BLOCCO?]+~ |
|
|
| Report Abuse |
|
|
myrkos
|
  |
| Joined: 06 Sep 2010 |
| Total Posts: 8072 |
|
|
| 24 Oct 2011 07:17 PM |
| add -llua and -llualib (i think) to the copile options |
|
|
| Report Abuse |
|
|
|
| 24 Oct 2011 07:47 PM |
| Thanks myrkos, but now it says that it can't find llualib. When I include just llib, it gives me a different file that says it can't find the symbol. (This is in 64-bit mode, compiling with 32-bit I'm given a message that says I'm ignoring liblua.a.) |
|
|
| Report Abuse |
|
|
|
| 24 Oct 2011 08:27 PM |
Thanks all! I got it to work with:
gcc -I/usr/local/include -L/usr/local/lib -llua ~/path.c
But is there anyway to shorten this (via aliases or something)? I edited my IDE to execute my programs with this as the default, but I was looking for another way to compile it with the Terminal. |
|
|
| Report Abuse |
|
|
XlegoX
|
  |
| Joined: 16 Jun 2008 |
| Total Posts: 14955 |
|
|
| 24 Oct 2011 08:47 PM |
"But is there anyway to shorten this (via aliases or something)? I edited my IDE to execute my programs with this as the default, but I was looking for another way to compile it with the Terminal."
That's exactly what a "Makefile" is for, I'm sure you've seen those before in projects. It's pretty tricky to write them, but a good skill to learn at some point. |
|
|
| Report Abuse |
|
|
|
| 24 Oct 2011 08:48 PM |
| Yes, I have seen them. I really need to make a formal list of "Things I Need to Learn" because I have a lot of items to put on it, including how to make Makefile stuff. |
|
|
| Report Abuse |
|
|