Skip to main content
GameDev.net gamedev.net
🔒 Locked

Compiling Lua into a VS 05 .lib - Link Error 4006

Started by jmau0438 May 5, 2009 at 9:42 PM 7 replies 2.9k views
Original Post
jmau0438
jmau0438
I recently downloaded Lua 5.1 and imported the source files into a visual studio 2005 project to produce a .lib file. There were a few speed bumps, but it all turned out fine, except for just one thing. I have no errors and only one warning, a duplicated symbol that is ignored by the compiler. I don't think that its a serious issue, but it's really buggin me that I can't get rid of the warning. Here is a copy/paste from the output panel of the warning message: lua.obj : warning LNK4006: _main already defined in luac.obj; second definition ignored I'm assuming there is a symbolic definition that is repeated in a couple of source files, but I can't find it. Any suggestions?
Codeka
Codeka
I think you're including too many .c file in your library project. luac.c contains the bytecode compiler which you can use to save the bytecode of a lua source file to disk, it's not meant to be included in the "main" LUA library, it's meant to be compiled as a standalone executable.

If you look at the Makefile, it's got the following rules:

LUA_A=	liblua.aCORE_O=	lapi.o lcode.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o \ 	lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o \   	lundump.o lvm.o lzio.oLIB_O=	lauxlib.o lbaselib.o ldblib.o liolib.o lmathlib.o loslib.o ltablib.o \  	lstrlib.o loadlib.o linit.o$(LUA_A): $(CORE_O) $(LIB_O)	$(AR) $@ $?	$(RANLIB) $@


So it's only those files (lapi.c, lcode.c, etc) that are meant to be included in the "main" library.
jmau0438
jmau0438
I did as you instructed and the problem went away (THANK YOU SO MUCH) by creating a brand new solution (starting over) and taking these steps:

1) I added these header files to build just the library

lua.h luaconf.h lualib.h lauxlib.h lua.hpp

2) Added these source files

lapi.c lcode.c ldebug.c ldo.c ldump.c lfunc.c lgc.c llex.c
lmem.c lobject.c lopcodes.c lparser.c lstate.c lstring.c
ltable.c ltm.c lundump.c lvm.c lzio.c
lauxlib.c lbaselib.c ldblib.c liolib.c lmathlib.c loslib.c
ltablib.c lstrlib.c loadlib.c linit.c

3) Excluded these source files

lua.c luac.c print.c

4) I added the _CRT_SECURE_NO_WARNINGS symbol to both debug & release to remove all the depreciation warnings at "Project -> Properties -> Configuration Properties -> Preprocessor -> Preprocessor Definitions"

However, after looking at the INSTALL & makefile files I now have to create an interpreter and compiler if I want to bring this one full circle.

1) Interpreter - Requires the Lua Library .lib file (that was just made) and the lua.c source file

2) Compiler - Requires the Lua Library .lib file (that was just made) and the luac.c & print.c source files

This process raises a few more questions (annoying I know, but I really need help):

QUESTION #1 - Should both the interpreter & compiler projects also be .libs? If not, then what?

QUESTION #2 - How do I tie them all together?

QUESTION #3 - Dude, I suck at importing .lib's and .dll's, and I'm using Visual Studio 2005. Can anyone break the process down for me? You know, STEP #1, STEP #2, ...and so on.

Thanks again
jmau0438
jmau0438
I'm assuming the interpreter is at least a command prompt project, and so I'm working the interpreter from that angle. Am I wrong?
jmau0438
jmau0438
I was able to get the Lua Library (.lib) file working by including it as a reference (project properties -> common properties -> references -> add new reference) in the interface project. I then included lua.c (which operates as the starting point to the project) and compiled with no problem, or so I thought. I threw in some breaks and a _getch() here and there and realized that it was exiting on a failure. Here is the lua main function:

//OTHER CODE ABOVE

#include

int main (int argc, char **argv) {

int status;
struct Smain s;

lua_State *L = lua_open(); /* create state */

if (L == NULL) {

l_message(argv[0], "cannot create state: not enough memory");
return EXIT_FAILURE;
}

s.argc = argc;
s.argv = argv;
status = lua_cpcall(L, &pmain, &s);
report(L, status);
lua_close(L);

return (status || s.status) ? _getch(), EXIT_FAILURE : EXIT_SUCCESS;

}

The conio include and the _getch were added by me. As I said before, it exits on failure. Can anyone shed some light?
jmau0438
jmau0438
I tinkered with it some more and it turns out that their is a problem. I tried accessing some aspects of Lua and received access violation errors at runtime.

I threw the following code after the "lua_State *L = lua_open();" declaration in the previously shown block of code:

//Open the basic library
luaopen_base ( L );
//Open the table library
luaopen_table ( L );
//Open the I/O library
luaopen_io ( L );
//Open the string library
luaopen_string ( L );
//Open the math library
luaopen_math ( L );

And recieved the following run-time errors:

'LuaInterpreter.exe': Loaded 'C:\LUA_5_1_LIB\LuaLibrary\release\LuaInterpreter.exe', Symbols loaded.
'LuaInterpreter.exe': Loaded 'C:\Windows\System32\ntdll.dll', No symbols loaded.
'LuaInterpreter.exe': Loaded 'C:\Windows\System32\kernel32.dll', No symbols loaded.
'LuaInterpreter.exe': Loaded 'C:\Windows\winsxs\x86_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.3053_none_d08d7bba442a9b36\msvcr80.dll', No symbols loaded.
'LuaInterpreter.exe': Loaded 'C:\Windows\System32\msvcrt.dll', No symbols loaded.
First-chance exception at 0x00405259 in LuaInterpreter.exe: 0xC0000005: Access violation reading location 0xbaadf019.
Unhandled exception at 0x00405259 in LuaInterpreter.exe: 0xC0000005: Access violation reading location 0xbaadf019.
The program '[3828] LuaInterpreter.exe: Native' has exited with code -1073741819 (0xc0000005).

Using break points, I discovered that (initially) it was happening at lua_openstring(), but after commenting it out the issue just migrated to another openning function call. I'm wondering if I included the .lib right, it may just be failing at "lua_open". I AM OFFICALLY STUCK, so any help would be appreciated.
Erluk
Erluk
Instead of building Lua yourself, you might want to use one of the pre-built versions at LuaBinaries.
Problems with Windows? Reboot! - Problems with Linux? Be root!
jmau0438
jmau0438
Thanks for the advise, but I wouldn't learn much that way.
Erluk
Erluk
You get run-time errors on luaopen_* because those have to be called from Lua.

Does the interpreter itself work as expected, i.e., do you get a command prompt where you can enter Lua commands? If it does, and still exits with EXIT_FAILURE, then you should examine the value of 'status' and 's.status' to find out what kind of error Lua encountered.

PS: Please use [ source ] tags for posting code.
Problems with Windows? Reboot! - Problems with Linux? Be root!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.