Talk:Compiling under VS2005: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
Line 161: Line 161:


Added /FORCE:MULTIPLE to Linker->Command Line->Additional Options
Added /FORCE:MULTIPLE to Linker->Command Line->Additional Options
==Other Fixes==
I'm just trying out these...
For tolower() error:
baseentity.cpp(57)
add #include <ctype.h>
after #include "vphysics/friction.h" (L 57)
Linker errors with wchar_t as values:
Client->;Properties->C/C++->Language
and set Treat wchar_t as Built in Type to No.
This is because the Valve library vgui_control.lib is compiled with the option - Treat wchar_t as Built in Type - set to No so they need to be the same.
An alternative fix is to recompile vgui_control.lib with the option set to Yes - its found in src\vgui2\controls. So you need to back up vgui_control.lib - found in src\lib\public and recompile it with the option set to yes and then copy that to where the original one was that you backed up.
For the error C2065: 'i' : undeclared identifier. There are two ways to fix this.
Easiest way is to go to Client->;Properties->C/C++->Language and set
Force Conformance in For Loop to No.
Alternative fix would be adding the "int"-declaration into code. That's how i did it before and how it's described above.
The problem with strdup doesn't happen in debug mode since Valve overrides strdup with their own strdup func.
The heap error only shows itself when using the debugger in release mode.
I believe it's because strdup() in the C library that comes with 2005 express uses new() instead of malloc().
So when Valve frees the memory using free() it gives the error. Here's the fix I hope...
..\tier1\stringpool.cpp(73)
CHANGE
pszNew = strdup( pszValue );
TO
#ifndef _debug
pszNew = (char*) malloc(sizeof(char) * (strlen(pszValue) + 1)); // Use Valve's malloc instead of strdup
strcpy(pszNew, pszValue);
#else
pszNew = strdup( pszValue ); // Use Valve's debug strdup
#endif
..\cl_dll\c_baseflex.cpp(921)
CHANGE
g_flexcontroller[g_numflexcontrollers++] = strdup( szName );
TO
#ifndef _debug
g_flexcontroller[g_numflexcontrollers] = (char*) malloc(sizeof(char) * (strlen(szName) + 1)); //Use V's malloc instead of strdup
strcpy(g_flexcontroller[g_numflexcontrollers++], szName);
#else
g_flexcontroller[g_numflexcontrollers++] = strdup( szName ); //Use V's debug strdup
#endif
BotPutInServer linker failures
Various BotPutInServer lines will fail to link in DEBUG mode.
Commenting the BotPutInServer lines out works just fine.
It may have some negative affect on bots.
I quite frankly have not looked into that stuff at all, other than to see that it breaks the build.
Fix:
A better way would be
adding hl2mp_bot_temp.h
and hl2mp_bot_temp.cpp
to the HL project under the Source Files->HL2MP folder.
hl2mp_bot_temp.h and hl2mp_bot_temp.cpp can both be found in yourmod/src/dlls/hl2mp_dll folder.


===Other Fixes / Comments===
===Other Fixes / Comments===

Revision as of 09:57, 11 February 2006

How to Compile with Visual C++ 2005 Express

steps till being able to compile with V C++ 05 Express:

required:

  • MS DirectX SDK
  • MS Platform SDK

Tools - Options: Projects and Solutions - VC++ Directories

upper right select "executable files" and enter "...\Microsoft Platform SDK\Bin" (replace ... with your path of course)

"include files" --> "...\Microsoft Platform SDK\Include" and "...\Microsoft DirectX SDK (December 2005)\Include"

"libary files" --> "...\Microsoft Platform SDK\Lib" & "...\Microsoft DirectX SDK (December 2005)\Lib\x86"


dbg.h

add

#pragma warning(disable : 4996)

after #pragma once (new line) to disable old, unsecure functions warning.


now the actual error fixes:

All projects

Many, many instances of "error C2065: 'i' : undeclared identifier". This is where there is code like:

for(int i=0; i<XXX; i++)
{
    //do something
}

for( i=0; i<YYY; i++)
{
    //do something else
}

Change the first line to:

int i;
for( i=0; i<XXX; i++)
''etc.''

to fix these problems.


Release-Compile:

client:

..\public\vstdlib\strtools.h(90):

inline char*	Q_strrchr (const char *s, char c)					{ return strrchr( (char *)s, c ); }

..\public\vstdlib\strtools.h(93) zu

inline char*	Q_strstr( const char *s1, const char *search )		{ return strstr( (char *)s1, search ); }

..\cl_dll\hud_bitmapnumericdisplay.cpp(159)

if( bStart || digit > 0 || pos <= pow((float)10,numSigDigits-1) )

..\game_shared\baseentity_shared.cpp(251)

char *s = strchr( (char *)szKeyName, '#' );

..\tier1\KeyValues.cpp(800)

char *subStr = strchr((char *)keyName, '/');


undeclared variable (add "int i;" in front of it, as mentioned before)

..\cl_dll\interpolatedvar.h(538)

..\public\sentence.cpp(735)

..\public\sentence.cpp(1098)

..\public\sentence.cpp(1168)


Linking Errors & Fixes:

Added msvcrt.lib and user32.lib to Linker->Input->Additional Dependencies (seperated each with a space(" "))

Added LIBC to Linker->Input->Ignore specific library

Added /FORCE:MULTIPLE to Linker->Command Line->Additional Options



hl:

vguiscreen.cpp(69)

char *s = strchr( (char *)szKeyName, '#' );

TemplateEntities.cpp(298)

int iMax = pow((double)10, (int)(strlen(ENTITYIO_FIXUP_STRING)-1)); // -1 for the &


Linking Errors & Fixes:

Added user32.lib to Additional Dependencies under Linker->Input

Added /FORCE:MULTIPLE to Linker->Command Line->Additional Options



Debug-Compile:

client:

...\public\tier0\memoverride.cpp line 405-430

Remove "_base" from those functions. Looks then like that:

#if defined(_DEBUG) && _MSC_VER >= 1300
void __cdecl _aligned_free(
void *
);
void * __cdecl _aligned_malloc(
size_t,
size_t
);
void * __cdecl _aligned_malloc_base(
size_t size,
size_t align
)
{
return _aligned_malloc(size, align);
}

void __cdecl _aligned_free_base(
void *memblock
)
{
_aligned_free(memblock);
}
#endif[/quote]


Linking Errors & Fixes:

Added msvcrtd.lib and user32.lib Linker->Input->Additional Dependencies

Added /FORCE:MULTIPLE to Linker->Command Line->Additional Options


hl:

...\dlls\ai_behavior_follow.cpp(2090)

//ASSERT_INVARIANT( sizeof(FollowerListIter_t) == sizeof(AI_FollowManagerInfoHandle_t) );


Linking Errors & Fixes:

Added user32.lib to Linker->Input->Additional Dependencies

Added /FORCE:MULTIPLE to Linker->Command Line->Additional Options

Other Fixes

I'm just trying out these...

For tolower() error:

baseentity.cpp(57)

add #include <ctype.h>

after #include "vphysics/friction.h" (L 57)


Linker errors with wchar_t as values:

Client->;Properties->C/C++->Language
and set Treat wchar_t as Built in Type to No.

This is because the Valve library vgui_control.lib is compiled with the option - Treat wchar_t as Built in Type - set to No so they need to be the same.

An alternative fix is to recompile vgui_control.lib with the option set to Yes - its found in src\vgui2\controls. So you need to back up vgui_control.lib - found in src\lib\public and recompile it with the option set to yes and then copy that to where the original one was that you backed up.


For the error C2065: 'i' : undeclared identifier. There are two ways to fix this.

Easiest way is to go to Client->;Properties->C/C++->Language and set Force Conformance in For Loop to No.

Alternative fix would be adding the "int"-declaration into code. That's how i did it before and how it's described above.


The problem with strdup doesn't happen in debug mode since Valve overrides strdup with their own strdup func. The heap error only shows itself when using the debugger in release mode. I believe it's because strdup() in the C library that comes with 2005 express uses new() instead of malloc(). So when Valve frees the memory using free() it gives the error. Here's the fix I hope...

..\tier1\stringpool.cpp(73) CHANGE

	pszNew = strdup( pszValue );

TO

	#ifndef _debug
		pszNew = (char*) malloc(sizeof(char) * (strlen(pszValue) + 1)); // Use Valve's malloc instead of strdup
		strcpy(pszNew, pszValue);
	#else
		pszNew = strdup( pszValue ); // Use Valve's debug strdup
	#endif


..\cl_dll\c_baseflex.cpp(921) CHANGE

	g_flexcontroller[g_numflexcontrollers++] = strdup( szName );

TO

		#ifndef _debug
			g_flexcontroller[g_numflexcontrollers] = (char*) malloc(sizeof(char) * (strlen(szName) + 1)); //Use V's malloc instead of strdup
			strcpy(g_flexcontroller[g_numflexcontrollers++], szName);
		#else
			g_flexcontroller[g_numflexcontrollers++] = strdup( szName ); //Use V's debug strdup
		#endif


BotPutInServer linker failures

Various BotPutInServer lines will fail to link in DEBUG mode. Commenting the BotPutInServer lines out works just fine. It may have some negative affect on bots. I quite frankly have not looked into that stuff at all, other than to see that it breaks the build.

Fix: A better way would be adding hl2mp_bot_temp.h and hl2mp_bot_temp.cpp to the HL project under the Source Files->HL2MP folder. hl2mp_bot_temp.h and hl2mp_bot_temp.cpp can both be found in yourmod/src/dlls/hl2mp_dll folder.


Other Fixes / Comments

got some info from this forumthreat

i had some errors in c_rope

fixed it once with:

taking the closing "}" from ( int iRenderCache = 0; iRenderCache < nRenderCacheCount; ++iRenderCache )

behind ++m_aRenderCache[iRenderCache].m_nCacheCount;

(means from line 231 (i think) to line 252)

i'm still trying to complete this so it will compile, hope i could help anyone...

greetz

User:Rotzi Jan 2006


grml...

doesn't work neither with express nor with full version... maybe i'm just stupid...

I'll try again this weekend and update here...

User:Rotzi Feb 2006


And still I'm having problems... Just tried it again, Release Client only, but did not get past 3 kinds of errors, wich all in all were 190 errors and 439 warnings...

I also noticed that including user32.lib and excluding LIBC did not change these error-numbers, so atleast up to that point, it did not need them... Still I'm only talking about client-Release Only.

User:Rotzi


Misc

I'll be getting a copy of Visual Studio 2005 (not express) in the next couple of weeks. Is there a problem compiling on it too or does anybody know yet? --AndrewNeo 07:11, 28 Jan 2006 (PST)

No, what i read is there are no Problems with normal, full Version of VS 05. --Rotzi 4 Fe 2006 (GMT+1)


Force:Multiple error in release - client

How come i get the error like described in the threat, but it won't be fixed by adding "/FORCE:MULTIPLE", but caused by that instead... caused means, without it it doesn't get to that error, or doesn't have it...

msvcrt.lib(MSVCR80.dll) : error LNK2005: _free already defined in memoverride.obj (thats the error)

Added /FORCE:MULTIPLE to Linker->Command Line->Additional Options (and that should be the solution)