Компиляция под VS2005/Старые SDK

From Valve Developer Community
Jump to: navigation, search
English (en)Deutsch (de)русский (ru)
... Icon-Important.png

Введение

Это архив требуемых изменений, необходимых для корректной работы старых версий компиляторов с Source движком. Это только для старых версий. SDK код новее чем Ноябрь 2006 не требует ниже перечисленных исправлений, вместо них, читайте статью Компиляция под VS2005.

Требования (другие SDK и их настройка)

Необходимые действия необходимы для обеспечения компиляции с Visual Studio C++ 2005 Express Edition:

Требуемые файлы

Настройка

Перейдите в Tools - Options: Projects and Solutions - VC++ Directories

  • В верхнем правом выпадающем окне, выберите "Executable files" и добавьте "...\Microsoft Platform SDK\Bin" (замените на правильный путь)
  • Затем выберите "Include files" и добавьте "...\Microsoft Platform SDK\Include" and "...\Microsoft DirectX SDK (December 2005)\Include"
  • Затем выберите "Library files" и добавьте "...\Microsoft Platform SDK\Lib" and "...\Microsoft DirectX SDK (December 2005)\Lib\x86"
  • Наконец, перейдите в свойства проектов hl и client и добавьте user32.lib в Linker->Input->Additional Dependencies (с пробелами между)

Настройка проекта

Отключение предупреждений Deprecated Declaration

Это исправление отключит предупреждения deprecated declaration, которые действительно являются лишь предупреждениями.

Они предупреждают, что используемые функции старые, и доступны более новые, безопасные версии, но это может быть проигнорировано.

..\public\tier0\dbg.h

добавьте

#pragma warning(disable : 4996)

после #pragma once (на новую линию), чтобы отключить старые предупреждения.

Отключение предупреждений

Это исправление удалит комментарии от объекта отладки.

Найдите:

#ifdef _WIN32
 	#ifdef _DEBUG
		#pragma comment(compiler)
		#pragma comment(exestr,"*** DEBUG file detected, Last Compile: " __DATE__ ", " __TIME__ " ***")
	#endif
#endif

Замените на:

#ifdef _WIN32
	#ifdef _DEBUG
		//#pragma comment(compiler)
		//#pragma comment(exestr,"*** DEBUG file detected, Last Compile: " __DATE__ ", " __TIME__ " ***")
	#endif
#endif

wchar_t Linker errors

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. Backing up vgui_control.lib is recommended - found in src\lib\public and recompile it with the option set to yes and then copy that to where the original lib was backed up.

Изменение кода

Основное

ошибка C2065: 'i' : undeclared identifier

Есть два способа исправить ошибку C2065: 'i' : undeclared identifier. Щелкните правой кнопкой мыши на client и hl, перейдите в C/C++ -> Language и установите

Force Conformance в For Loop на No.

Альтернативное исправление - добавление "int"-объявления в код.

Конфигурация Финальной Компиляции

Общие исправления

..\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, '/');

Memoverride Linking Ошибки & Исправления:

memoverride.obj : error LNK2019: unresolved external symbol __aligned_malloc_base referenced in function __aligned_malloc memoverride.obj : error LNK2019: unresolved external symbol __aligned_free_base referenced in function __aligned_free

Линии 405 - 430 в memoverride.cpp:

До:

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

После:

#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

Исправление клиента (client.dll)

Linking Ошибки & Исправления:

Добавьте msvcrt.lib и user32.lib в Linker->Input->Additional Dependencies (каждая разделена пробелом(" "))

Добавьте LIBC в Linker->Input->Ignore Specific Library

Добавьте /FORCE:MULTIPLE в Linker->Command Line->Additional Options

Исправление HL (server.dll)

..\dlls\vguiscreen.cpp(69)

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

..\dlls\TemplateEntities.cpp(298)

int iMax = pow((double)10, (int)(strlen(ENTITYIO_FIXUP_STRING)-1)); // -1 for the &
Изменение function-run в function-link (ошибка C3867)

..\dlls\hl2_dll\weapon_rpg.cpp

* (150)  SetTouch( &CMissile::MissileTouch );
* (153)  SetThink( &CMissile::IgniteThink );
* (256)  SetThink( &CMissile::SeekThink );
* (311)  SetThink( &CMissile::AugerThink );
* (435)  SetThink( &CMissile::SeekThink );
* (881)  SetTouch( &CAPCMissile::APCMissileTouch );
* (916)  SetThink( &CAPCMissile::BeginSeekThink );
* (925)  SetThink( &CAPCMissile::AugerStartThink );
* (938)  SetThink( &CMissile::AugerThink );
* (945)  SetThink( &CAPCMissile::ExplodeThink );
* (955)  SetThink( &CMissile::SeekThink );
* (2058) pLaserDot->SetContextThink( &CLaserDot::LaserThink, gpGlobals->curtime + 0.1f, g_pLaserDotThink );

..\dlls\hl2_dll\weapon_physcannon.cpp

* (2480) SetContextThink( &CWeaponPhysCannon::WaitForUpgradeThink, gpGlobals->curtime + 6.0f, s_pWaitForUpgradeContext );
* (2502) SetContextThink( &CWeaponPhysCannon::WaitForUpgradeThink, gpGlobals->curtime + 0.1f, s_pWaitForUpgradeContext );

..\dlls\hl2_dll\weapon_crossbow.cpp(324)

SetThink( &CBaseEntity::SUB_Remove );

..\dlls\hl2_dll\npc_BaseZombie.cpp(160)

static int s_iAngryZombies = 0;

..\dlls\baseentity.cpp(57) Вы должны вставить в конце #includes

#include <ctype.h>

Linking исправления

Добавьте msvcrt.lib и user32.lib в Linker->Input->Additional Dependencies (каждая разделена пробелом(" "))

Добавьте /FORCE:MULTIPLE в Linker->Command Line->Additional Options

Конфигурация Отладочной Компиляции

Linking Ошибки & Исправления

Добавьте msvcrtd.lib и user32.lib Linker->Input->Additional Dependencies

Добавьте /FORCE:MULTIPLE в Linker->Command Line->Additional Options

Клиент

...\public\tier0\memoverride.cpp линии 405-430 (410-435 Если вы добавили функции выше (релиз hl))

Удалите "_base" из этих функций и его в return-var. Будет выглядеть так:

  • (406/411)
void    __cdecl _aligned_free(
  • (410/415)
void *  __cdecl _aligned_malloc(
  • (415/420)
void * __cdecl _aligned_malloc_base(
  • (420/425)
    return _aligned_malloc(size, align);
  • (423/428)
void __cdecl _aligned_free_base(
  • (427/432)
    _aligned_free(memblock);

HL

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

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


Linking Ошибки & Исправления:

Добавьте user32.lib в Linker->Input->Additional Dependencies

Добавьте /FORCE:MULTIPLE в Linker->Command Line->Additional Options

Добавьте LIBCMTD в hl->Properties->Configuration Properties->Linker->Input->Ignore Specific Library

Другие исправление

Note.pngNote:В конечном счете, они не нужны...

STRDUP

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)

Измените

	pszNew = strdup( pszValue );

на

	#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)

Измените

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

на

		#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

(worked for me, didn't have to do this with SP)

Various BotPutInServer lines will fail to link in DEBUG mode. Commenting the BotPutInServer lines out works just fine. This 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.

Исправление: Лучше бы

	добавить hl2mp_bot_temp.h и hl2mp_bot_temp.cpp 
	в HL проект под Source Files->папка HL2MP.
	hl2mp_bot_temp.h и hl2mp_bot_temp.cpp находятся в папке yourmod/src/dlls/hl2mp_dll.

Предупреждения

..\public\tier0\memoverride.cpp

  • (107)
__declspec(restrict) __declspec(noalias) void *malloc( size_t nSize ) 
  • (111)
__declspec(noalias) void free( void *pMem ) 
  • (116)
__declspec(restrict) __declspec(noalias) void *realloc( void *pMem, size_t nSize ) 
  • (121)
__declspec(restrict) __declspec(noalias) void *calloc( size_t nCount, size_t nElementSize )
  • add this function to line 136 (i don't get what this is for???)
void *_calloc_impl( size_t nCount, size_t nElementSize )
{
return calloc(nCount, nElementSize);
} 

comment out _heap_init() and _heap_term(), means, (i don't get what this is for???)

comment out everything from line 298 to line 303 (these lines are these lines if you added the function *_calloc_impl (which is 4 lines long) to line 136.

Список оставшихся ошибок

SP Debug Client

..\public\tier0\commonmacros.h(29) : warning C4005: 'ARRAYSIZE': Makro-Neudefinition
pathto\microsoft platform sdk\include\winnt.h(950): Siehe vorherige Definition von 'ARRAYSIZE'

..\public\tier0\memoverride.cpp(413)(418)(418) : warning C4565 (I should be able to fix that, will check that again later...)

LINK : warning LNK4075: ignoring /INCREMENTAL due to /FORCE specification.

LONG LIST of .obj files, all with warning:

warning LNK4224: /COMMENT is no longer supported; ignored.

msvcrt.lib(MSVCR80.dll) : warning LNK4006: _free already defined in "memoverride.obj"; second definition ignored

.\cl_dll___Win32_HL2_Debug/client.dll : warning LNK4088: image being generated due to /FORCE option; image may not run.

SP Debug hl

..\public\tier0\memdbgon.h(83) : warning C4996: 'strcpy' (can stay like that...)

same for 'wcscpy' and 'strtok'

+some new double-definitions (LIBCMTD.lib, ...)

+the errors of SP Debug Client (LNK4224: /COMMENT, warning C4005: 'ARRAYSIZE')

Статьи по теме