Setting up Lua for Visual C++ 6

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Setting up Lua for Visual C++ 6

Fabio Reis Cecin
Hi. I'm using Visual C++ 6 and trying to compile a very simple program
that makes use of the Lua precompiled binaries for Windows/VC6:

#include <lua.h>
int main() { 
  lua_State *s = lua_open(256);
  return 0;
}

The VC6 linker complains that it can't find lua_open():

lua.obj : error LNK2001: unresolved external symbol "struct lua_State * __cdecl 
lua_open(int)" (?lua_open@@YAPAUlua_State@@H@Z)
Debug/lua.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

I tried using the libs in the "windows/vc6" directory in the Lua FTP. I have
included lua.lib and lualib.lib in Project >> Settings >>
Linker >> Object/Library modules, and added the directory path of the
libs in Tools >> Options >> Directories >> Library files.

Could someone "hold my hand" and tell me what files I need from the
Lua FTP, where to put them, and how to setup VC6 to use them so it
can compile this simple pre-hello-world example?

Thanks,

- Fabio

Reply | Threaded
Open this post in threaded view
|

Re: Setting up Lua for Visual C++ 6

Eero Pajarre-2
[hidden email] wrote:
Hi. I'm using Visual C++ 6 and trying to compile a very simple program
that makes use of the Lua precompiled binaries for Windows/VC6:

#include <lua.h>
int main() { lua_State *s = lua_open(256);
  return 0;
}

The VC6 linker complains that it can't find lua_open():

lua.obj : error LNK2001: unresolved external symbol "struct lua_State * __cdecl lua_open(int)" (?lua_open@@YAPAUlua_State@@H@Z)
Debug/lua.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.


Looks like you got bitten by the C++ name mangling.

Try the following change:
----------
extern "C" {
#include <lua.h>
}

int main() {
  lua_State *s = lua_open(256);
  return 0;
}
------------

If this doesn't help, then it is time to
check other things. I personally include lua into
my project by adding the source files to to the VC
project. Because of their small size, I have
never felt any need to use a .lib for Lua.

		Eero






Reply | Threaded
Open this post in threaded view
|

Re: Setting up Lua for Visual C++ 6

Denis Andreev
In reply to this post by Fabio Reis Cecin

ftcb> #include <lua.h>
ftcb> int main() { 
ftcb>   lua_State *s = lua_open(256);
ftcb>   return 0;
ftcb> }

You must use:

extern "C" {
#include <lua.h>
}

This is a C calling conversation missmatch.


--Denq


Reply | Threaded
Open this post in threaded view
|

Re: Setting up Lua for Visual C++ 6

Fabio Reis Cecin
In reply to this post by Eero Pajarre-2
On 13 Aug 2002 at 16:59, Eero Pajarre wrote:

> Looks like you got bitten by the C++ name mangling.
> 
> Try the following change:
> ----------
> extern "C" {
> #include <lua.h>
> }
> 
> int main() {
>    lua_State *s = lua_open(256);
>    return 0;
> }
> ------------

It worked! But now there's this strange warning:

LINK : warning LNK4098: defaultlib "LIBC" conflicts with use of other libs; use 
/NODEFAULTLIB:library

But I think it is unharmful, the program compiled and ran fine.

> If this doesn't help, then it is time to
> check other things. I personally include lua into
> my project by adding the source files to to the VC
> project. Because of their small size, I have
> never felt any need to use a .lib for Lua.
> 
> 		Eero

I will try that too.

Thanks!

- Fabio

Reply | Threaded
Open this post in threaded view
|

RE: Setting up Lua for Visual C++ 6

Nick Trout-4
In reply to this post by Fabio Reis Cecin
> I get that same 
> "LINK : warning LNK4098: defaultlib "LIBC" conflicts with use 
> of other libs;
> use /NODEFAULTLIB:library" 
> warning when I compile debug-enabled code with a non-debug 
> Lua library.
> Haven't bothered to find where to switch it off (does someone 
> know?) since
> it doesn't trouble that much.

Sounds to me like you're linking single threaded and multithreaded libraries
together. Go into the project settings and under (I think) code generation -
make it all single or multi. You'll need to do this for debug and release
settings.



Reply | Threaded
Open this post in threaded view
|

RE: Setting up Lua for Visual C++ 6

Asko Kauppi-2
I get that same 
"LINK : warning LNK4098: defaultlib "LIBC" conflicts with use of other libs;
use /NODEFAULTLIB:library" 
warning when I compile debug-enabled code with a non-debug Lua library.
Haven't bothered to find where to switch it off (does someone know?) since
it doesn't trouble that much.

-asko


> -----Original Message-----
> From:	[hidden email] [SMTP:[hidden email]]
> Sent:	Tuesday, August 13, 2002 5:22 PM
> To:	Multiple recipients of list
> Subject:	Re: Setting up Lua for Visual C++ 6
> 
> On 13 Aug 2002 at 16:59, Eero Pajarre wrote:
> 
> > Looks like you got bitten by the C++ name mangling.
> > 
> > Try the following change:
> > ----------
> > extern "C" {
> > #include <lua.h>
> > }
> > 
> > int main() {
> >    lua_State *s = lua_open(256);
> >    return 0;
> > }
> > ------------
> 
> It worked! But now there's this strange warning:
> 
> LINK : warning LNK4098: defaultlib "LIBC" conflicts with use of other
> libs; use 
> /NODEFAULTLIB:library
> 
> But I think it is unharmful, the program compiled and ran fine.
> 
> > If this doesn't help, then it is time to
> > check other things. I personally include lua into
> > my project by adding the source files to to the VC
> > project. Because of their small size, I have
> > never felt any need to use a .lib for Lua.
> > 
> > 		Eero
> 
> I will try that too.
> 
> Thanks!
> 
> - Fabio
###########################################
This message has been scanned by F-Secure Anti-Virus for Microsoft Exchange.


Reply | Threaded
Open this post in threaded view
|

Re: Setting up Lua for Visual C++ 6

Kelmar K. Firesun
In reply to this post by Nick Trout-4
----- Original Message -----
From: "Nick Trout" <[hidden email]>
To: "Multiple recipients of list" <[hidden email]>
Sent: Tuesday, August 13, 2002 10:27 AM
Subject: RE: Setting up Lua for Visual C++ 6


>
> > I get that same
> > "LINK : warning LNK4098: defaultlib "LIBC" conflicts with use
> > of other libs;
> > use /NODEFAULTLIB:library"
> > warning when I compile debug-enabled code with a non-debug
> > Lua library.
> > Haven't bothered to find where to switch it off (does someone
> > know?) since
> > it doesn't trouble that much.
>
> Sounds to me like you're linking single threaded and multithreaded
libraries
> together. Go into the project settings and under (I think) code
generation -
> make it all single or multi. You'll need to do this for debug and release
> settings.
>
>

If this doesn't work, try going into the project settings for the libraries,
and under the Library tab, add a "/nodefaultlib" to the Project Options
section.

You can also add a line to the source to do this:

#pragma comment(linker, "/nodefaultlib")

Note, if you try the #pramga option, be sure to add it to an include file
that
ONLY the library(s) use.  If your main project uses this line you'll run
into
other issues.

I should point out that the above warning is harmless (if just not annoying)
most of the time.

Kelmar K. Firesun (IRL: Bryce Simonds)