🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

LUA Information

Started by
11 comments, last by MatrixCubed 21 years, 8 months ago
Hello all, I'm hunting for some information on LUA (http://www.lua.org/). Right now my problem is in the initial stage: linker errors when calling any function (unresolved external functions).
  
#include <stdio.h>
#include <lua.h>

///////////////////////////////////////////////////////////////////////////////


#pragma comment(lib, "lualib.lib")
#pragma comment(lib, "lua.lib")

///////////////////////////////////////////////////////////////////////////////


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

	lua_State* lState = NULL;
	lState = lua_open(100);
	lua_close(lState);


	return 0;

}

///////////////////////////////////////////////////////////////////////////////

  
I'm using the Win32 binary distribution of version 4 in VC6. Libs and headers are included in the correct locations. I'm assuming I'll have to compile the lib files and hope this works?
        
--------------------Configuration: LUA_Test00 - Win32 Debug--------------------
Linking...
Main.obj : error LNK2001: unresolved external symbol "void __cdecl lua_close(struct lua_State *)" (?lua_close@@YAXPAUlua_State@@@Z)
Main.obj : error LNK2001: unresolved external symbol "struct lua_State * __cdecl lua_open(int)" (?lua_open@@YAPAUlua_State@@H@Z)
Output/LUA_Test00[d].exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.

LUA_Test00[d].exe - 3 error(s), 0 warning(s)
  
If anyone has experience with initial setup of LUA, I'd much appreciate a quick pointer in the right direction. Google is a little cryptic with this sort of thing... Thanks! MatrixCubed
http://MatrixCubed.cjb.net [edited by - MatrixCubed on October 24, 2002 2:59:09 AM]
Advertisement
A common error when starting out. The Lua libraries are linked as C libraries, so you need to call their functions as such. So you need to enclose the function declarations in an extern "C" block.

Change this:
#include <lua.h>#include <lualib.h> 
To this:
extern "C" {#include <lua.h>#include <lualib.h>} 


Good luck.

Don''t listen to me. I''ve had too much coffee.
Thanks, that worked.

Is this in the documentation anywhere? Or perhaps you came across this another way?



MatrixCubed
http://MatrixCubed.cjb.net

if you haven''t found this site yet, spend a lot of time on it; extremely useful for all things Lua.

http://lua-users.org

in particular, check out the Wiki. That''s where all the good stuff is.

Don''t listen to me. I''ve had too much coffee.
quote: Original post by MatrixCubed
Is this in the documentation anywhere? Or perhaps you came across this another way?

It''s a common problem you''ll run into when using C libraries with C++ code. Some libary authors are thoughtful enough to put the extern "C" stuff in the header for you, and some are not.



[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost | Asking Questions | Organising code files | My stuff ]
Hi,

I am using Lua too but it seems there is some problem with conflicting libraries when I embed it. I get following error messages but can''t figure out how to solve them...

LIBC.lib(crt0dat.obj) : error LNK2005: _exit already defined in msvcrtd.lib(MSVCRTD.dll)
LIBC.lib(crt0init.obj) : error LNK2005: ___xc_z already defined in msvcrtd.lib(cinitexe.obj)
LIBC.lib(crt0init.obj) : error LNK2005: ___xc_a already defined in msvcrtd.lib(cinitexe.obj)
LIBC.lib(crt0init.obj) : error LNK2005: ___xi_z already defined in msvcrtd.lib(cinitexe.obj)
LIBC.lib(crt0init.obj) : error LNK2005: ___xi_a already defined in msvcrtd.lib(cinitexe.obj)
LIBC.lib(crt0dat.obj) : warning LNK4006: _exit already defined in msvcrtd.lib(MSVCRTD.dll); second definition ignored
LIBC.lib(crt0init.obj) : warning LNK4006: ___xc_z already defined in msvcrtd.lib(cinitexe.obj); second definition ignored
LIBC.lib(crt0init.obj) : warning LNK4006: ___xc_a already defined in msvcrtd.lib(cinitexe.obj); second definition ignored
LIBC.lib(crt0init.obj) : warning LNK4006: ___xi_z already defined in msvcrtd.lib(cinitexe.obj); second definition ignored
LIBC.lib(crt0init.obj) : warning LNK4006: ___xi_a already defined in msvcrtd.lib(cinitexe.obj); second definition ignored
Creating library Debug/SimDll.lib and object Debug/SimDll.exp
LINK : warning LNK4098: defaultlib "msvcrtd.lib" conflicts with use of other libs; use /NODEFAULTLIB:library
LINK : warning LNK4098: defaultlib "LIBC" conflicts with use of other libs; use /NODEFAULTLIB:library
Debug/SimDll.dll : fatal error LNK1169: one or more multiply defined symbols found

I open the auxiliary libraries with:

lua_baselibopen(L);
lua_strlibopen(L);
lua_mathlibopen(L);
lua_iolibopen(L);

and if I leave the last away (lua_iolibopen), it compiles and runs (but crashes badly when I try to run a script which contains errors...). But even though, I get warnings about conflicting libraries.

Please help me to solve that problem, I''ve been on this already 2 days (;_
...anyone can help? I am desesperate...
hmmm.... I remember having problems similar to that at one point. Do the problems go away if you compile in release mode?

Don''t listen to me. I''ve had too much coffee.
Thank you Sneftel,

In release mode I have the same problem.

I read once something about a similar problem in this forum a while back (but the search function is unfortunately down...) and someone explained you have to change something in the settings under "C/C++" then "Code Generation" and select something under "Use run-time library"... I can''t remember more and if the problem was really the same. Anyway, I tried all different possibilities, but could only create even more errors!!!
Floating: I had that same problem once using the clapack library.

See this link. Basically you need to link to the same run time library that the lua libs were compiled against. In my case it just meant adding a /MD switch to the command line. It looks the same in yours.

This topic is closed to new replies.

Advertisement