Bug Summary for Visual Studio (2): LNK1201 Error at every build
In this post we discuss the LNK1201 Error at every build in Visual Studio 2003. This issue of LNK1201 Error at every build is considered as a bug for Visual Studio 2003 which is caused by the fact that the pdb files are always opened or occupied by the debugger in Visual Studio 2003. We try to explain the reason behind it and give several solutions to resolve this LNK1201 Error.
How LNK1201 Error phenomenon looks like:
The phenomenon for LNK1201 Error looks like this: When I build the project at the first time and it goes OK, after I did some modification on the source code, and try to build it again, it just reports me with the LNK1201 error message. This happens every time I try to build the project after I modified the code while it seems the only solution to avoid this is to close VS, and to re-open the project, in this way I would be able to build it ONE time again (after first build, close again, ect) which is really annoying.
The Reason Behind LNK1201 Error:
The reasoning might be different, but one common reason for this is: it is usually when the application exit incorrectly or anomaly which leads to the fact that the pdb file is not closed when it finishes (thus LNK1201 error). In this case, the LNK1201 problem will not occur if the program exits correctly.
In worse case, no matter the application exit correctly or incorrectly, the annoying LNK1201 will show anyways as I describe previously, for this, it is the bug for Visiual Studio 2003, because VS 2003 is holding the PDB open when it shouldn’t, and it is the debugger which occupies the pdb file. This results in that, for next time, we won’t be able to write anything into the open pdb files (thus LNK1201 error).
Several Solutions to resolve LNK1201 Error:
As far as I know, there are basically two different ways to resolve this LNK1201 error issue and make it work. Both of them involve doing some pre-build things: in project property -> build events-> pre-build events, we add some pre-build command to either rename the occupied pdb file or close all the open handlers for the pdb file (free pdb).
The first is to rename the pdb file into a different one (only rename works, delete or move the pdb file would fail because the pdb file is occupied by VS 2003 debugger, e.g, if you try to delete the pdb file, it just reports access deinied message), in this case, I just write a C program to rename the occupied pdb file with another different name. PS: I don’t suggest to use windows cmd, “rename file.pdb differentname.pdb” because this command would fail after its first run. After the first run, the file with the name differentname.pdb is there and it will make the rename command report an error with fail in the following execution.
Another solution could be using handle.exe from microsoft. That is, we mannuly run some script to execute the handle.exe which could find all the open handlers for the pdb file and force close them. Another option is to use a freeware on lock or unlock the pdb file. More details about this solution could be found in the following references.
In this post we discussed the LNK1201 Error at every build in Visual Studio 2003 which is considered as a bug for Visual Studio 2003 and is caused by the fact that the pdb files are always opened or occupied by the debugger in Visual Studio 2003. We try to explain the reason behind it and give several solutions (rename or use handle.exe) to resolve this LNK1201 Error.
（转载本站文章请注明作者和出处 烟客旅人 sigmainfy — http://www.sigmainfy.com，请勿用于任何商业用途）