473,386 Members | 1,673 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Maybe OT, compiles in DevCPP, not in MSVC 2008

I'm trying to compile some source code to interface LUA into C++. When I
compile in MSVC++ Express 2008, however, I get the error (among others):

....\luastate.h(129) : error C2027: use of undefined type
'cpplua::LuaFunction'
....\luastate.h(63) : see declaration of 'cpplua::LuaFunction'

So I'm trying to track this down. I see that there is a function trying to
return LuaFunction Like this:

LuaFunction createFunction(cppluaFunction* f);
template <typename TLuaFunction createFunction(T& object,
int(T::*f)(LuaState*)) {
LuaFunction res = createFunctionFromObject();
lua_pushlightuserdata(L, &res);
lua_pushlightuserdata(L, reinterpret_cast<void*>(&object));
void* ptmf = lua_newuserdata(L, sizeof(int(T::*)(LuaState*)));
std::memcpy(ptmf, &f, sizeof(int(T::*)(LuaState*)));
lua_pushcclosure(L, LuaState::generalTemplateFunction<T>, 2);
lua_settable(L, cppluaTableIndex);
return res;
}

And the error is showing up on the closing bracket which is line 129. So
then I try to back track where LuaFunction is defined and find in some
unrelated class:
friend class LuaFunction;

The I try to find out if luafunction.h is included, and it is, but in a roud
about way. I find there are some interdepedancies between luastate.h and
luafunction.h

luafuncion.h includes
luaobject.h which includes
luastate.h

before any other custom headers in each.

luastate.h, however, does not include luafunction.h

luastate.cpp incluses luastate.h before any other header.

So how the heck does DevCPP compile this mess? At the point of luastate.h
line 129 LuaFunction has not been declared. Yet DevCPP goes ahead and
compiles it happily.

Unfortuanlly, the project I eventually want to use this lua interface in is
a MSVC++ 2008 project and the lua library I have is for microsoft (it failes
with many errors linking in DevCPP).

What is the culprit here? I'm suspecting it some DevCPP "extention"
although not thought of as that, as DevCPP just goes ahead and figures out
how to compile it somehow when logically it shouldn't. There are so many
interdependancies in thsi code that to fix it might to do.

Any help would be appreciated.

--
Jim Langston
ta*******@rocketmail.com
Jun 27 '08 #1
1 1663
On Jun 5, 1:04 am, "Jim Langston" <tazmas...@rocketmail.comwrote:
I'm trying to compile some source code to interface LUA into
C++. When I compile in MSVC++ Express 2008, however, I get
the error (among others):
...\luastate.h(129) : error C2027: use of undefined type
'cpplua::LuaFunction'
...\luastate.h(63) : see declaration of 'cpplua::LuaFunction'
So I'm trying to track this down. I see that there is a
function trying to return LuaFunction Like this:
LuaFunction createFunction(cppluaFunction* f);
template <typename TLuaFunction createFunction(T& object,
int(T::*f)(LuaState*)) {
LuaFunction res = createFunctionFromObject();
lua_pushlightuserdata(L, &res);
lua_pushlightuserdata(L, reinterpret_cast<void*>(&object));
void* ptmf = lua_newuserdata(L, sizeof(int(T::*)(LuaState*)));
std::memcpy(ptmf, &f, sizeof(int(T::*)(LuaState*)));
lua_pushcclosure(L, LuaState::generalTemplateFunction<T>, 2);
lua_settable(L, cppluaTableIndex);
return res;
}
Supposing that what the compiler really means by "undefined
type" is what is called an incomplete type in the standard. If
LuaFunction is an incomplete type at this point, then "If a type
used in a non-dependent name is incomplete at the point at which
a template is defined but is complete at the point at which an
instantiation is done, and if the completeness of that type
affects whether or not the program is well-formed or affects the
semantics of the program, the program is ill-formed; no
diagnostic is required." (This is from my copy of the C++03
standard, where it is marked as an insertion, in response to
core issue 206. This sentence isn't present in C++98, but
presumably, it was the intent.)
And the error is showing up on the closing bracket which is
line 129. So then I try to back track where LuaFunction is
defined and find in some unrelated class:
friend class LuaFunction;
Which doesn't make the name visible outside of that class.
The I try to find out if luafunction.h is included, and it is,
but in a roud about way. I find there are some
interdepedancies between luastate.h and luafunction.h
luafuncion.h includes
luaobject.h which includes
luastate.h
before any other custom headers in each.
Which means anything defined in luastate.h cannot use the
contents of luaobject.h or luafuncion.h, since luastate.h will
be included before the bodies of those headers.
luastate.h, however, does not include luafunction.h
And it wouldn't change anything if it did, supposing that all of
the .h files have header guards. (Without any header guards, if
luastate.h included luafunction.h, and luafunction.h included
luastate.h, you'd have an infinite inclusion. Undefined
behavior, but almost certainly either a compiler error or a
compiler crash.)
luastate.cpp incluses luastate.h before any other header.
So how the heck does DevCPP compile this mess? At the point
of luastate.h line 129 LuaFunction has not been declared. Yet
DevCPP goes ahead and compiles it happily.
A lot of older compilers treated templates more or like macros.
They barely parsed them enough to know where they ended where
the template was defined, and only really did any analysis when
the template was instantiated. I suppose that LuaFunction *is*
fully defined when the function is instantiated. (And of
course, regardless of how templates are instantiated, the
compiler doesn't really need the complete definition of
LuaFunction until it starts generating code, and it won't start
generating code until there is an instantiation.)

Note that this technique is still legal. The standard specified
templates in a way that allowed the compiler to detect a good
number of errors in the templates definition, but all of these
errors are considered "undefined behavior"---the compiler is not
required to diagnose them. (The standard really needs another
category for this: either the compiler diagnoses an error, or
the code works. There are a number of such cases in the
standard, and classifying them as "undefined behavior" is
overdoing it, IMHO.)
Unfortuanlly, the project I eventually want to use this lua
interface in is a MSVC++ 2008 project and the lua library I
have is for microsoft (it failes with many errors linking in
DevCPP).
What is the culprit here? I'm suspecting it some DevCPP
"extention" although not thought of as that, as DevCPP just
goes ahead and figures out how to compile it somehow when
logically it shouldn't. There are so many interdependancies
in this code that to fix it might to do.
Not so much an "extention", I think, but simply an artifact of
the compiler's age (or a simplification in the implementation of
the compiler). And while I can't quite parse your last
sentence, you are going to have to fix some of the dependencies.
I don't think that there's any other way around it. (Note that
one solution that sometimes helps is to declare the functions,
*then* include the headers needed for their implementation, then
define them. Or to put the declarations and the definitions in
separate header files; the client headers will then include
first all of the declarations they need, then all of the
definitions.)

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Jun 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Eric Brunel | last post by:
Hi all, We're trying to communicate with Microsoft Visual C++ 6.0 via COM to make it perform a few operations. Our main need is to set a breakpoint on a given line in a given file. We ended up...
2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
0
by: Leor Zolman | last post by:
The Intel C++ version of STLFilt (my STL Error Message Decryptor utility) has now been updated to support Intel C++ 8 (currently in Beta) along with version 7. All three MSVC libraries are...
4
by: GeoTrail | last post by:
Hey people. I'm brand spanking new to the wonderful world of C++. I just want to ask the opinnions of the more experienced users if they know of DevCpp by Bloodshed and if they think it's a good...
8
by: Chris Stankevitz | last post by:
I can't tell you how frusterated I and my coworkers are with "MSVC 7.1 .net 2003" (what am I supposed to call this thing anyway?). Compiling and linking take twice as long with "MSVC 7.1 .net...
6
by: ma | last post by:
Hello, Some questions about upgrading to MSVC 2008. 1- I am using MSVC2005, Do you recommend that I upgrade to MSVC 2008 Beta 2? 2- When the MSVC2008 will be officially release? 3- Where...
30
by: Dave -Turner | last post by:
So I just downloaded Bloodshed devcpp, opened up the Hello example, compiled it, no problems ..... well, except one - the exe is 474,990 bytes! What's the secret to compiling small exes? Thanks
17
by: fl | last post by:
Hi, I am learning C++ from the following C++ website, which has some very good small examples. For the second Fraction example, which has five files: Main.cpp Fraction.cpp Fraction.h...
2
by: BruceWho | last post by:
I downloaded boost1.35.0 and built it with following command: bjam --toolset=msvc-7.1 --variant=release --threading=multi -- link=shared --with-system stage and it failed to compile, error...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.