C++ Question VC++ problem

Scrooge McDuck

Addon Developer
Addon Developer
Joined
Mar 18, 2008
Messages
515
Reaction score
30
Points
28
Location
The Netherlands
Website
orbitermap.no-ip.org
Please, try to carefully read all the advise given to you here, before you post!

Usually, there are no such things as idiotic questions. Don't hesitate to ask anything you want on this forum.
But in any case, carefully read and try first. Obviously, he meant the help-search (MSDN page), and after this, he adviced to use the search/replace function.
What has been reached with the 101 replies on this thread, might have been possible in just under 30. Not that this really is a problem, but it makes you think.

Please note that forum rule 1 also counts for individual posts.

With kindest regards,
mcduck
 

T.Neo

SA 2010 Soccermaniac
Addon Developer
Joined
Jun 22, 2008
Messages
6,368
Reaction score
0
Points
0
I both successfully compiled DG and Shuttle A.
The stricmp warnings went away when I dealt with afxres.h.

I've been scared of trying to fix things myself because I'm not really sure what I am doing, and I'm worried that I may worsen the situation.

And I apologise for any stupid questions. I'm still new to a lot of this.

EDIT:
Stupid question:
I get this
.\ShuttleA.cpp(42) : error C2065: 'i' : undeclared identifier

Here is what I think is line 42:
double f = (aoa-AOA) / (AOA[i+1]-AOA);

I'm suspecting that there is something wrong with the .cpp.
What do I change and how?

 
Last edited:

dbeachy1

O-F Administrator
Administrator
Orbiter Contributor
Addon Developer
Donator
Beta Tester
Joined
Jan 14, 2008
Messages
9,217
Reaction score
1,563
Points
203
Location
VA
Website
alteaaerospace.com
Preferred Pronouns
he/him
That error means that the the variable 'i' is not declared in the current scope. In this case it is caused by a bug in the .cpp file that slipped through because Visual C++ 6.0 (which was originally used to develop the ShuttleA) has a bug that incorrectly keeps 'i' in-scope outside of the 'for' loop on the the previous line:

Code:
for (int i = 0; i < nabsc-1 && AOA[i+1] < aoa; i++);  // under VC++ 6.0, 'i' incorrectly remains in-scope after this loop completes
double f = (aoa-AOA[i]) / (AOA[i+1]-AOA[i]);  // compile error (correctly!) occurs under later (fixed) compiler versions

The fix is to declare 'i' outside the 'for' loop as follows:

Code:
int i; // new line: declare 'i' outside the loop so its value may be used after the loop finishes
for (i = 0; i < nabsc-1 && AOA[i+1] < aoa; i++);
double f = (aoa-AOA[i]) / (AOA[i+1]-AOA[i]);  // this will work now since 'i' is still in-scope

There are several other places in the sample code (including the DG source) that also must be modified in order to compile under newer compilers.

I've been scared of trying to fix things myself because I'm not really sure what I am doing, and I'm worried that I may worsen the situation.


C++ is quite difficult if you don't know what you're doing, so I highly recommend picking up a good C++ book and spending a few weeks going through it and compiling/editing example code in the book to learn the basics of the language. [Amazon.com has some good C++ books.]
 

Hielor

Defender of Truth
Donator
Beta Tester
Joined
May 30, 2008
Messages
5,580
Reaction score
2
Points
0
EDIT:
Stupid question:
I get this
.ShuttleA.cpp(42) : error C2065: 'i' : undeclared identifier

Here is what I think is line 42:
double f = (aoa-AOA) / (AOA[i+1]-AOA);

I'm suspecting that there is something wrong with the .cpp.
What do I change and how?



/facepalm

You already had this problem in shuttlePB, in this post: http://www.orbiter-forum.com/showthread.php?p=77544 The problem was already solved for you there.
 

T.Neo

SA 2010 Soccermaniac
Addon Developer
Joined
Jun 22, 2008
Messages
6,368
Reaction score
0
Points
0
The problem was already solved for you there.

I knew that it had to do with that, but I didn't know what to change.
I must take Doug's advice and read a few books.
Although I must admit I'm not to good with languages...
 

tblaxland

O-F Administrator
Administrator
Addon Developer
Webmaster
Joined
Jan 1, 2008
Messages
7,320
Reaction score
25
Points
113
Location
Sydney, Australia
T.Neo said:
Sorry for the idiot question, but which search box?
On the menu: "Help|Search". It is your friend ;)

I've been scared of trying to fix things myself because I'm not really sure what I am doing, and I'm worried that I may worsen the situation.

And I apologise for any stupid questions. I'm still new to a lot of this.
Just try. I am pretty much self-taught and you learn by trying. So far I haven't managed to create any life-threatening situations, the worst you thing you will injure is your pride ;).

Some tips: Think about what the error message is trying to tell you. If it is not obvious, type the error in to the help search box. Google often helps, too.

Also, based on your questions, I strongly recommend you get a clear understanding of "scope". The aforementioned Help|Search returns this fairly concise article:
http://msdn.microsoft.com/en-us/library/b7kfh662(VS.80).aspx
And a slightly more verbose article here (it also touches on lifetime, which is also particularly important when dealing with classes):
http://en.wikibooks.org/wiki/C++_Programming/Code/Scope
 

T.Neo

SA 2010 Soccermaniac
Addon Developer
Joined
Jun 22, 2008
Messages
6,368
Reaction score
0
Points
0
Just try. I am pretty much self-taught and you learn by trying. So far I haven't managed to create any life-threatening situations, the worst you thing you will injure is your pride ;).

Self-taught and trial and error work, as this is how I learn't pretty much everything I know about computers.
I'll give it a bash. I have some ideas coming up that need coding...
 

CaptnDave

New member
Joined
Feb 11, 2009
Messages
28
Reaction score
1
Points
0
Location
Saskatchewan
I'm still having a problem with LNK2005, 2001 and 2019, kinda like T. Neo. I have the code generation set to M/T and have all the libraries set up and working. I don't know what I'm doing wrong, but here is my error output:

Code:
1>------ Build started: Project: ShuttlePB, Configuration: Debug Win32 ------
1>Linking...
1>MSVCRT.lib(ti_inst.obj) : error LNK2005: "private: __thiscall type_info::type_info(class type_info const &)" (??0type_info@@AAE@ABV0@@Z) already defined in LIBCMT.lib(typinfo.obj)
1>MSVCRT.lib(ti_inst.obj) : error LNK2005: "private: class type_info & __thiscall type_info::operator=(class type_info const &)" (??4type_info@@AAEAAV0@ABV0@@Z) already defined in LIBCMT.lib(typinfo.obj)
1>   Creating library .\Debug/ShuttlePB.lib and object .\Debug/ShuttlePB.exp
1>LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library
1>ShuttlePB.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) int i" (__imp_?i@@3HA)
1>libcpmtd.lib(xdebug.obj) : error LNK2019: unresolved external symbol __malloc_dbg referenced in function "void * __cdecl operator new(unsigned int,struct std::_DebugHeapTag_t const &,char *,int)" (??2@YAPAXIABU_DebugHeapTag_t@std@@PADH@Z)
1>libcpmtd.lib(xdebug.obj) : error LNK2019: unresolved external symbol __free_dbg referenced in function "void __cdecl operator delete(void *,struct std::_DebugHeapTag_t const &,char *,int)" (??3@YAXPAXABU_DebugHeapTag_t@std@@PADH@Z)
1>.\Debug/ShuttlePB.dll : fatal error LNK1120: 3 unresolved externals
1>Build log was saved at "file://c:\Program Files\Orbiter\Orbitersdk\samples\ShuttlePB\Debug\BuildLog.htm"
1>ShuttlePB - 6 error(s), 2 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
 
Last edited:

tblaxland

O-F Administrator
Administrator
Addon Developer
Webmaster
Joined
Jan 1, 2008
Messages
7,320
Reaction score
25
Points
113
Location
Sydney, Australia
I'm still having a problem with LNK2005, 2001 and 2019, kinda like T. Neo. I have the code generation set to M/T and have all the libraries set up and working. I don't know what I'm doing wrong, but here is my error output:
It looks like you are compiling in debug mode because the compiler is trying to link against LIBCPMTD.lib. LIBCMT.lib and MSVCRT.lib should be ignored for that configuration. You may also need to ignore MSVCIRT.lib and LIBC.lib, if you have not already done so. Also make sure that LIBCMTD.lib is not ignored.

EDIT: Not sure why the compiler is trying to externally link "int i". Is this vanilla ShuttlePB code, ie, you've made no changes to it?
 

CaptnDave

New member
Joined
Feb 11, 2009
Messages
28
Reaction score
1
Points
0
Location
Saskatchewan
Nope, all I do is click 'Build Solution'. Code Generation is set to 'Multi-Thread'. I've ignored those things you just said, and got this:
Code:
1>------ Build started: Project: ShuttlePB, Configuration: Debug Win32 ------
1>Compiling...
1>ShuttlePB.cpp
1>Linking...
1>   Creating library .\Debug/ShuttlePB.lib and object .\Debug/ShuttlePB.exp
1>ShuttlePB.obj : error LNK2001: unresolved external symbol "const type_info::`vftable'" (??_7type_info@@6B@)
1>ShuttlePB.obj : error LNK2019: unresolved external symbol "void __cdecl operator delete(void *)" (??3@YAXPAX@Z) referenced in function "public: virtual void * __thiscall LaunchpadItem::`scalar deleting destructor'(unsigned int)" (??_GLaunchpadItem@@UAEPAXI@Z)
1>ShuttlePB.obj : error LNK2019: unresolved external symbol "void __cdecl operator delete[](void *)" (??_V@YAXPAX@Z) referenced in function "public: virtual void * __thiscall LaunchpadItem::`vector deleting destructor'(unsigned int)" (??_ELaunchpadItem@@UAEPAXI@Z)
1>ShuttlePB.obj : error LNK2019: unresolved external symbol "void __stdcall `eh vector destructor iterator'(void *,unsigned int,int,void (__thiscall*)(void *))" (??_M@YGXPAXIHP6EX0@Z@Z) referenced in function "public: virtual void * __thiscall LaunchpadItem::`vector deleting destructor'(unsigned int)" (??_ELaunchpadItem@@UAEPAXI@Z)
1>ShuttlePB.obj : error LNK2001: unresolved external symbol __fltused
1>ShuttlePB.obj : error LNK2001: unresolved external symbol __purecall
1>ShuttlePB.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) int i" (__imp_?i@@3HA)
1>ShuttlePB.obj : error LNK2019: unresolved external symbol "void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z) referenced in function _ovcInit
1>ShuttlePB.obj : error LNK2019: unresolved external symbol "void * __cdecl operator new[](unsigned int,struct std::_DebugHeapTag_t const &,char *,int)" (??_U@YAPAXIABU_DebugHeapTag_t@std@@PADH@Z) referenced in function "public: char * __cdecl std::_DebugHeapAllocator<char>::allocate(unsigned int,void const *)" (?allocate@?$_DebugHeapAllocator@D@std@@QAAPADIPBX@Z)
1>ShuttlePB.obj : error LNK2019: unresolved external symbol "struct std::_DebugHeapTag_t const & __cdecl std::_DebugHeapTag_func(void)" (?_DebugHeapTag_func@std@@YAABU_DebugHeapTag_t@1@XZ) referenced in function "public: char * __cdecl std::_DebugHeapAllocator<char>::allocate(unsigned int,void const *)" (?allocate@?$_DebugHeapAllocator@D@std@@QAAPADIPBX@Z)
1>ShuttlePB.obj : error LNK2019: unresolved external symbol __CxxThrowException@8 referenced in function "public: char * __cdecl std::_DebugHeapAllocator<char>::allocate(unsigned int,void const *)" (?allocate@?$_DebugHeapAllocator@D@std@@QAAPADIPBX@Z)
1>ShuttlePB.obj : error LNK2001: unresolved external symbol "public: __thiscall std::exception::exception(class std::exception const &)" (??0exception@std@@QAE@ABV01@@Z)
1>ShuttlePB.obj : error LNK2019: unresolved external symbol "public: __thiscall std::exception::exception(char const * const &)" (??0exception@std@@QAE@ABQBD@Z) referenced in function "public: __thiscall std::bad_alloc::bad_alloc(char const *)" (??0bad_alloc@std@@QAE@PBD@Z)
1>ShuttlePB.obj : error LNK2001: unresolved external symbol "public: virtual char const * __thiscall std::exception::what(void)const " (?what@exception@std@@UBEPBDXZ)
1>ShuttlePB.obj : error LNK2019: unresolved external symbol "public: virtual __thiscall std::exception::~exception(void)" (??1exception@std@@UAE@XZ) referenced in function "public: virtual __thiscall std::bad_alloc::~bad_alloc(void)" (??1bad_alloc@std@@UAE@XZ)
1>ShuttlePB.obj : error LNK2019: unresolved external symbol _free referenced in function "void __cdecl std::_DebugHeapDelete<void>(void *)" (??$_DebugHeapDelete@X@std@@YAXPAX@Z)
1>LINK : error LNK2001: unresolved external symbol __DllMainCRTStartup@12
1>.\Debug/ShuttlePB.dll : fatal error LNK1120: 17 unresolved externals
1>Build log was saved at "file://c:\Program Files\Orbiter\Orbitersdk\samples\ShuttlePB\Debug\BuildLog.htm"
1>ShuttlePB - 18 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

The only thing I've changed in the code is added
Code:
__declspec( dllimport ) int i;
__declspec( dllexport ) void func();

I was told by the help thing that that was how to compile a .dll, without that, I get this error
Code:
1>c:\program files\orbiter\orbitersdk\samples\shuttlepb\shuttlepb.cpp(46) : error C2065: 'i' : undeclared identifier
 

Biscuit

Member
Donator
Joined
May 12, 2008
Messages
181
Reaction score
0
Points
0
Location
Navarre, FL
I'm getting the same 'unresolved external symbol' errors when I try to compile the vanila shuttlePB myself ... compiles like a champ in debug mode ... release gets errors.

I'm using Visual Studio 2008 Pro (a legitimate licensed copy) ... the compiler setup didn't really cover it, options in different places ... I'm sure it's something I'm doing wrong, but it was late last night and I haven't dug any deeper into it yet.

Ah, well ... if all else fails, the Express version should be able to live with pro without much problem.
 

Bj

Addon Developer
Addon Developer
Donator
Joined
Oct 16, 2007
Messages
1,886
Reaction score
11
Points
0
Location
USA-WA
Website
www.orbiter-forum.com
I was told by the help thing that that was how to compile a .dll, without that, I get this error
Code:
1>c:\program files\orbiter\orbitersdk\samples\shuttlepb\shuttlepb.cpp(46) : error C2065: 'i' : undeclared identifier

see here

http://www.orbiterwiki.org/wiki/Free_Compiler_Setup

Look at the C++ language change ;

Code:
// Calculate lift coefficient [Cl] as a function of aoa (angle of attack) over -Pi ... Pi// Implemented here as a piecewise linear functiondouble LiftCoeff (double aoa){    const int nlift = 9;    static const double AOA[nlift] = {-180*RAD,-60*RAD,-30*RAD,-1*RAD,15*RAD,20*RAD,25*RAD,60*RAD,180*RAD};    static const double CL[nlift]  = {       0,      0,   -0.1,     0,   0.2,  0.25,   0.2,     0,      0};    static const double SCL[nlift] = {(CL[1]-CL[0])/(AOA[1]-AOA[0]), (CL[2]-CL[1])/(AOA[2]-AOA[1]),                                  (CL[3]-CL[2])/(AOA[3]-AOA[2]), (CL[4]-CL[3])/(AOA[4]-AOA[3]),                      (CL[5]-CL[4])/(AOA[5]-AOA[4]), (CL[6]-CL[5])/(AOA[6]-AOA[5]),                                        (CL[7]-CL[6])/(AOA[7]-AOA[6]), (CL[8]-CL[7])/(AOA[8]-AOA[7])};    for (int i = 0; i < nlift-1 && AOA[i+1] < aoa; i++);       [B]int i;[/B]    [B]for (i = 0; i < nlift-1 && AOA[i+1] < aoa; i++);[/B]    return CL[i] + (aoa-AOA[i])*SCL[i];}

You have to put the ( int i; ) in front of the for loop. Then it will compile :cheers:

edit: sorry, the code isnot displaying properly. The website shows it better :)
 

Hielor

Defender of Truth
Donator
Beta Tester
Joined
May 30, 2008
Messages
5,580
Reaction score
2
Points
0
I'm getting the same 'unresolved external symbol' errors when I try to compile the vanila shuttlePB myself ... compiles like a champ in debug mode ... release gets errors.

I'm using Visual Studio 2008 Pro (a legitimate licensed copy) ... the compiler setup didn't really cover it, options in different places ... I'm sure it's something I'm doing wrong, but it was late last night and I haven't dug any deeper into it yet.

Ah, well ... if all else fails, the Express version should be able to live with pro without much problem.
I have successfully compiled Orbiter addons using VS 2008 Pro, so I know that it does work.
 

tblaxland

O-F Administrator
Administrator
Addon Developer
Webmaster
Joined
Jan 1, 2008
Messages
7,320
Reaction score
25
Points
113
Location
Sydney, Australia
Nope, all I do is click 'Build Solution'. Code Generation is set to 'Multi-Thread'.
But do you have the Debug or Release configuration active? There should be an entry on the Standard toolbar which shows which configuration you have active. If not, you can go to Build|Configuration manager (may be different for 2008, I am using 2005) to see which is active. Also, when you go to the Project|Properties dialog, make sure you are editing the active configuration (will look like Configuration: Active(Debug) at the top).

It looks like Debug is active to me because it is trying to link in the debug runtime functions. If not, there must be other causes. Lets eliminate one at a time.

I've ignored those things you just said, and got this:
I can replicate those errors exactly in Debug config and by ignoring LIBCMTD.lib and LIBCPMTD.lib. Make sure they are not on your ignore list. To make it easier, in future posts where you have link errors, can you please post your entire ignore list.

The only thing I've changed in the code is added
Code:
__declspec( dllimport ) int i;
__declspec( dllexport ) void func();
I was told by the help thing that that was how to compile a .dll, without that, I get this error
Delete those, it is wrong. See what BJ said. You probably were reading the help file in the context of link errors but it is not a link error, it is an out of scope error.
 

Biscuit

Member
Donator
Joined
May 12, 2008
Messages
181
Reaction score
0
Points
0
Location
Navarre, FL
Hooray ... got a clean 'Release' build ... another thread had suggested ignoring both "msvcrt.lib" and "msvcirt.lib" ...

Let it use the 'msvcrt.lib', and the linker errors go away.

I'm happy ... now, if I could just get VS2008 to let me create a template ... :)

... I do most of my stuff in VB.net or vbscript for work ... C++ is a bit of a learning curve ... but it's something new and shiny.

--------------------------------

*Wahoo!

Got a fresh new dll compiled and working in Orbiter using VS2008pro ... admittedly, it doesn't actually do anything except define the docking ports ... it's for one of Greg Burch's SBB modules (thank you Greg for some wonderful meshes :speakcool: ) ... but scenario editor recognizes it just fine.

... not that Vinka's stuff isn't great ... but a real DLL seems to be easier to work with in scenario editor.

:p
 
Last edited:

tblaxland

O-F Administrator
Administrator
Addon Developer
Webmaster
Joined
Jan 1, 2008
Messages
7,320
Reaction score
25
Points
113
Location
Sydney, Australia

CaptnDave

New member
Joined
Feb 11, 2009
Messages
28
Reaction score
1
Points
0
Location
Saskatchewan
Ok, it works. Working libraries for me are:
Additional Dependencies: kernel32.lib user32.lib gdi32.lib oldnames.lib
Ignore Specific Libraries: msvcirt.lib;libcpmtd.lib;libcmt.lib;libc.lib
Code Generation is: MD
Configuration: Runtime

Thanks so much for all your help. Now I can get to work making cool ships!

Thanks again!
 

Biscuit

Member
Donator
Joined
May 12, 2008
Messages
181
Reaction score
0
Points
0
Location
Navarre, FL
I finally got mine working with /MT (finally found where they stashed that option in VS2008), ignoring msvcirt.lib and msvcrt.lib.
Turned off debugging in the linker also just in case.

Increased the size of the dlls just a bit, but hopefully it will remove the need to
have any special runtime modules.

Hard for me to tell for sure since my machine has had so much crap loaded on it over time that I've probably got almost every runtime module under the sun in here somewhere. LOL

Would anyone willing to test a couple of dlls for me?
 
E

ex-orbinaut

Guest
Hooray ... got a clean 'Release' build ... another thread had suggested ignoring both "msvcrt.lib" and "msvcirt.lib" ...

Let it use the 'msvcrt.lib', and the linker errors go away.

Must be talking about my thread... I am very sorry if it mislead you, I found the same problems, and hastened to correct it on the thread.:embarrassed:

I'm glad you got it working but that is not a universal solution, I'm afraid. I'll save my typing - this post sums up why fairly well: http://www.orbiter-forum.com/showthread.php?p=93707#post93707 :cheers:

Thank you so much, tblaxland, for those links! Understanding is growing all the time with this kind help.

Increased the size of the dlls just a bit, but hopefully it will remove the need to have any special runtime modules.

.....

Would anyone willing to test a couple of dlls for me?

On the other hand, my dll got even smaller. From 72k (VC++2003) to 55k (the debug version VC++ 2008) to 47k (the release version VC++ 2008). It IS pretty simple, with one animation, some thrusters, rcs and an airfoil. And so far it runs computers with no other runtime modules installed.

Is there any sort of standard procedure that ensures maximum compatibility with this compiler set up business, which works generally? Or is it pretty much a case by case situation, depending on your includes, h files, OAPI usage, and so on, then followed by testing on several computers to see if it works?

I would be glad to test your dlls, but I do not know if it would be of any value to you for me to do so, as we are at exactly the same stage in this, even down to the from VB to VC++ conversion!
 
Top