Sign in to follow this  

[Solved] Lua and Visual C++ Express 2005, lib and dll problems

This topic is 4016 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I wanted to do some experimenting and add Lua scripting to my game engine just to see what the buzz was all about. So I created a test project, compile and everything worked first try. yay me \o/ Since it worked so well, what could go wrong ? So I try to include Lua in my game engine by reproducing the same step. Compiling and linking without Lua = OK, Executing gives me the sweet job of seeing my game engine work Compiling and linking with Lua but calling no lua function = OK, Executing works just as well Compiling and linking with Lua and calling lua_open and lua_close = OK but Executing say it can't find msvcr80.dll Weird I didn't to have it in my test project. So I copy the dll in my game engine folder. Oops !
Windows has triggered a breakpoint in HexEngine.exe.

This may be due to a corruption of the heap, and indicates a bug in HexEngine.exe or any of the DLLs it has loaded.

The output window may have more diagnostic information
The output window says :
'HexEngine.exe': Loaded 'C:\_Benoit\Development\HexEngine\Debug\HexEngine.exe', Symbols loaded.
'HexEngine.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll', No symbols loaded.
'HexEngine.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll', No symbols loaded.
'HexEngine.exe': Loaded 'C:\_Benoit\Development\HexEngine\lua5.1.dll', Binary was not built with debug information.
'HexEngine.exe': Loaded 'C:\_Benoit\Development\HexEngine\msvcr80.dll', No symbols loaded.
'HexEngine.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll', No symbols loaded.
'HexEngine.exe': Loaded 'C:\WINDOWS\system32\opengl32.dll', No symbols loaded.
'HexEngine.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll', No symbols loaded.
'HexEngine.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll', No symbols loaded.
'HexEngine.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll', No symbols loaded.
'HexEngine.exe': Loaded 'C:\WINDOWS\system32\user32.dll', No symbols loaded.
'HexEngine.exe': Loaded 'C:\WINDOWS\system32\glu32.dll', No symbols loaded.
'HexEngine.exe': Loaded 'C:\WINDOWS\system32\ddraw.dll', No symbols loaded.
'HexEngine.exe': Loaded 'C:\WINDOWS\system32\dciman32.dll', No symbols loaded.
First-chance exception at 0x7c90eae0 in HexEngine.exe: 0xC0000005: Access violation reading location 0x00000130.
R6034
An application has made an attempt to load the C runtime library incorrectly.
Please contact the application's support team for more information.
Windows has triggered a breakpoint in HexEngine.exe.

This may be due to a corruption of the heap, and indicates a bug in HexEngine.exe or any of the DLLs it has loaded.

The output window may have more diagnostic information
First-chance exception at 0x7c964ed1 in HexEngine.exe: 0xC0000142: DLL Initialization Failed.
Unhandled exception at 0x7c964ed1 in HexEngine.exe: 0xC0000142: DLL Initialization Failed.


The only difference I can see between both projet is that one use main() the other WinMain() Anybody with pointer that could help me debug this ? Some code TestLua
#include <stdio.h>
#pragma comment( lib, "./contrib/lua/lua5.1.lib" )
extern "C" {
	#include "./contrib/lua/lua.h"
	#include "./contrib/lua/lualib.h"
	#include "./contrib/lua/lauxlib.h"
}

/* the Lua interpreter */
lua_State* L;

static int average(lua_State *L)
{
	/* get number of arguments */
	int n = lua_gettop(L);
	double sum = 0;
	int i;

	/* loop through each argument */
	for (i = 1; i <= n; i++)
	{
		/* total the arguments */
		sum += lua_tonumber(L, i);
	}

	/* push the average */
	lua_pushnumber(L, sum / n);

	/* push the sum */
	lua_pushnumber(L, sum);

	/* return the number of results */
	return 2;
}

int main ( int argc, char *argv[] )
{
	/* initialize Lua */
	L = lua_open();

	/* load Lua base libraries */
	luaL_openlibs(L);

	/* register our function */
	lua_register(L, "average", average);

	/* run the script */
	luaL_dofile(L, "test.lua");

	/* cleanup Lua */
	lua_close(L);

	/* pause */
	printf( "Press enter to exit..." );
	getchar();

	return 0;
}


HexEngine.h (lot of code removed)
// Link with the appropriate OpenGL's lib
#pragma comment( lib, "./contrib/lua/lua5.1.lib" )
#pragma comment( lib, "opengl32.lib" )
#pragma comment( lib, "glu32.lib" )


extern "C" {
	#include "./contrib/lua/lua.h"
	#include "./contrib/lua/lualib.h"
	#include "./contrib/lua/lauxlib.h"
}



HexEngine.cpp
BOOL CHexEngine::initHexEngine()
{
	window.setTitle("HexTesting");

	/* the Lua interpreter */
	lua_State* L;
	/* initialize Lua */
	L = lua_open();

	/* load Lua base libraries */
	luaL_openlibs(L);
	lua_close(L);


	return TRUE;
}


I'm using Visual C++ Express 2005 with PSDK installed. Don't hesitate to ask for more information :) [Edited by - Tioneb on December 16, 2006 12:33:06 PM]

Share this post


Link to post
Share on other sites
I used to have the same problem, what I did was just stoped using the DLL and link a static library ( wich I compiled my self from the Lua sources )..

I hope it helps

Share this post


Link to post
Share on other sites
Ok using the static lib solved my problems, Thanks

For the records (if somebody have the same issue and find this thread) here's what I did :

1. Downloaded lua5_1_1_Sources.zip from LuaBinaries
2. Opened lua5.1/mak.vs2005/lua5.1.sln and builded the solution twice (because the first time, since the .lib was not already created, 2 projects didn't build
3. Copied lua5.1/lib/static/lua5.1.lib and lua5.1/lua5.1/include/* in my project folder
5. In VS C++ Express 2005 : Project > MyProject Properties
Configuration Properties > Linker > Input
Additionnal Dependencies = $(ProjectDir)/pathtostaticlib/lua5.1.lib
Ignore Specific Library = LIBCMT.lib (I was getting a lot of linker error without that)

And now everything works \o/

Share this post


Link to post
Share on other sites

This topic is 4016 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this