我的环境:WIN7 64旗舰版 + VS2003

以下问题很多人碰到,没发现神马好的解决方法:

fatal error LNK1201: error writing to program database 'D:\vs2003\Test.pdb';
check for insufficient disk space, invalid path, or insufficient privilege

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

幸好该pdb文件,可以重命名(VS2003运行时不能删除),且重命名后工程可以正常编译,

于是就有了解决方法:

1.在预编译事件中将该pdb文件重命名,就是这么简单。

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

人工重命名太痛苦了,于是我写了个小程序,代码如下:


// RenamePdb.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <time.h>

bool RenameFile(const char *pszFilePath);

int _tmain(int argc, _TCHAR* argv[])
{
printf("%s", "***************** Welcome to RenamePdb ********** \n");
printf("RenamePdb收到参数个数:%d \n", argc);
for (int i = 0; i < argc; i++)
{
printf("[参数%d] %s \n", i + 1, argv[i]);
}

if (argc > 1)
{
printf("%s \n", "文件重命名结果:");
for (int i = 1; i < argc; i++)
{
RenameFile(argv[i]);
}
}



printf("%s", "***************** RenamePdb Exit ***************** \n");
//getchar();
return 0;
}


// 文件重命名
bool RenameFile(const char *pszFilePath)
{
if (pszFilePath == NULL)
{
return false;
}

// time
char szTime[64] = {0};
time_t now;
struct tm *timenow;
time(&now);
timenow = localtime(&now);
if (timenow != NULL)
{
sprintf(szTime, "%4d%02d%02d%02d%02d%02d.pdb",
timenow->tm_year + 1900,
timenow->tm_mon + 1,
timenow->tm_mday,
timenow->tm_hour,
timenow->tm_min + 1,
timenow->tm_sec);
}

char szNewFile[256] = {0};
char szTmp[256] = {0};
strcpy(szTmp, pszFilePath);

// 将D:\12\34\56.pdb变成D:\12\34\
char *pszTmp = szTmp + strlen(szTmp) - 1;
int iCount = 0;
while(iCount++ <= 260)
{
if (*pszTmp == '\\')
{
pszTmp++;
*pszTmp = '\0';
break;
}
pszTmp--;
}


strcpy(szNewFile, szTmp);
strcat(szNewFile, szTime);

int iRet = rename(pszFilePath, szNewFile);
if (iRet == 0)
{
printf("[success] %s \n", szNewFile);
}
else
{
printf("[failed] %s \n", szNewFile);
}
return true;
}


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

使用方法:

1.将RenamePdb.exe拷贝到VS2003的以下安装目录:
D:\VS\Microsoft Visual Studio .NET 2003\Vc7\bin

2.在VS2003的工程属性中,
工程-->>>属性-->>>Build Events-->>>Pre-Build Event--------->>>Command Line
设置如下:
RenamePdb.exe  $(TargetDir)$(TargetName).pdb

3.大工告成。

fatal error LNK1201: error writing to program database_VS2003


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

RenamePdb.exe 程序及工程源码下载地址

效果截图:

fatal error LNK1201: error writing to program database_WIN7 64_02