c++ and lua

Started by
1 comment, last by Lith 13 years, 11 months ago
I have been trying to use lua with c++, but i cant get this basic program to work properly. I tried google but i didnt get the answer This is my code:

#include <stdio.h>

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

lua_State* L;

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

	luaL_openlibs(L);

	lua_close(L);

	return 0;
}

These are the errors:

main.obj : error LNK2019: unresolved external symbol _lua_close referenced in function _main
main.obj : error LNK2019: unresolved external symbol _luaL_openlibs referenced in function _main
main.obj : error LNK2019: unresolved external symbol _luaL_newstate referenced in function _main

I think that unresolved externals are to do with library files and the linker not finding functions and varibles in any file after it's read the header file. But i put all the header files in the right place because it's not complaining about that, i put the 2 lib files that i got with the lua source code with all the other VC++ lib files
Advertisement
Well, this is definitely a linking problem...

What is most likely happening is that they are in the VC++ folder, but you still are not telling your program to link with the libraries.

Try adding them in the project properties under Linking:

1)Right-click on your project.
2)Click Properties.
3)On the left find Linker.
4)Under it find and open Input.
5)Add the libraries to "Additional Dependencies."

Hope this helps!
Thanks! it now compiles and runs

This topic is closed to new replies.

Advertisement