Unresolved External errors while building C++ solutions - by anandkj_ace

Status : 

  By Design<br /><br />
		The product team believes this item works according to its intended design.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 541805 Comments
Status Closed Workarounds
Type Bug Repros 0
Opened 3/13/2010 10:33:56 PM
Access Restriction Public



I randomly get build failures comprising of "unresolved external" errors. These errors are random in the sense, that a perfectly valid solution will stop compiling all of a sudden and start giving the following error. After 50-60 failures, it will compile fine again, despite having made no changes to the code. The problem comes and goes randomly.

A project might build fine one moment, and will completely fail the next moment if I build it again without changing the code at all.

To double check that it is not an issue with my code, I compiled it in Visual Studio 2008 and it works flawlessly.

1>  Touching "Debug\Hw5.unsuccessfulbuild".
1>  All outputs are up-to-date.
1>Debug\sarray.obj : warning LNK4042: object specified more than once; extras ignored
1>sample_main.obj : error LNK2019: unresolved external symbol "public: void __thiscall sarray::status(void)" (?status@sarray@@QAEXXZ) referenced in function _main
1>sample_main.obj : error LNK2019: unresolved external symbol "public: int __thiscall sarray::set(int,int,double)" (?set@sarray@@QAEHHHN@Z) referenced in function _main
1>sample_main.obj : error LNK2019: unresolved external symbol "public: int __thiscall sarray::memoryUsed(void)" (?memoryUsed@sarray@@QAEHXZ) referenced in function _main
1>sample_main.obj : error LNK2019: unresolved external symbol "public: __thiscall sarray::sarray(int,int)" (??0sarray@@QAE@HH@Z) referenced in function _main
1>d:\Anand's\Docs\Visual Studio 2010\Projects\Hw5\Debug\Hw5.exe : fatal error LNK1120: 4 unresolved externals
1>Build FAILED.
1>Time Elapsed 00:00:01.50
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Sign in to post a comment.
Posted by Microsoft on 4/1/2010 at 3:34 PM
We are resolving the issue since we have not heard from you for a while. Please reactivate the issue if this is still a problem for you.

Thank you for using the beta product!

Li Shao, Project and Build Team
Posted by Microsoft on 3/18/2010 at 10:55 AM
Thank you for reporting the issue to us. The linker problem you are seeing could be caused by the build order. Or in other words, some of your projects are built before the projects they depend on are built. For example, in the error log you have, could you check if the project (let's name it A) that defines sarray::memoryUsed is built before the current project (let's name it B) is built? if it is not, please make a project to project reference from B to A. That can ensure the correct build order.

MSBuild cannot handle perfectly with the build ordering when build dependencies are expressed both through the solution dependencies and project to project reference, that is why we advice people to use project to project reference to define build dependency.

In general, if your application is converted from previous version and they have the build dependency already set in the solution, the conversion process will change the build dependency to project to project to project reference. However, if you have C++ and C# mixed solution, you may need to do the project to project reference manually. You can take a look of this blog post: http://blogs.msdn.com/vcblog/archive/2010/03/02/visual-studio-2010-c-project-upgrade-guide.aspx. There is a section about Build order/Project to project reference and possible random build failure in mixed C++/C# situation.

Please let me know if this helps you troubleshoot the problem.

Li Shao, Project and Build Team

Posted by Microsoft on 3/15/2010 at 3:38 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)