Thursday, December 17, 2009 11:24 PMI am using the Boost library under Express Beta 2 to do some simple unit testing. In order to do this you need to use the Project Dependencies option when you right click on a project to link the library the unit tests use to the unit testing project. But for some reason even tho I have the PrimeFactor project linked to the BoostUnitTest project through project dependencies i am getting a linker error. Here is the error.
1>------ Build started: Project: PrimeFactors, Configuration: Debug Win32 ------ 1> PrimeFactors.cpp 1> PrimeFactors.vcxproj -> C:\Users\blewisjr\documents\visual studio 2010\Projects\BoostUnitTest\Debug\PrimeFactors.lib 2>------ Build started: Project: BoostUnitTest, Configuration: Debug Win32 ------ 2> TestPrimeFactors.cpp 2>TestPrimeFactors.obj : error LNK2019: unresolved external symbol "public: static class std::list<int,class std::allocator<int> > __cdecl PrimeFactors::Generate(int)" (?Generate@PrimeFactors@@SA?AV?$list@HV?$allocator@H@std@@@std@@H@Z) referenced in function "public: void __thiscall OneHasNoFactors::test_method(void)" (?test_method@OneHasNoFactors@@QAEXXZ) 2>C:\Users\blewisjr\documents\visual studio 2010\Projects\BoostUnitTest\Debug\BoostUnitTest.exe : fatal error LNK1120: 1 unresolved externals ========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped =========
Bill Lewis Jr.
Friday, December 18, 2009 7:29 AMIn VS2010, the build system look at the project to project reference to determine if certain libs need to be passed to the linker. You may want to change the project dependencies to project to project reference instead.
When the projects from previous version of Visual Studio are converted to VS2010, project dependencies are converted to project to project dependencies. This change ensures that all project dependencies are captured in the project file.
Project and Build team
- Marked As Answer by blewisjr Friday, December 18, 2009 10:02 PM
Friday, December 18, 2009 10:02 PMThanks worked like a charm.
Bill Lewis Jr.
Wednesday, March 03, 2010 4:45 PM
It used to be (VS2008 for example) that a project dependency on a static library would automatically result in linking the right configuration (Debug|Release) of the library.
Either VS2010 lost that ability with the move to msbuild, or I don't know how to create a project to project "reference" with native C++.
VS 2005 documents it http://msdn.microsoft.com/en-us/library/ms235517.aspx like:
How to: Organize Project Output Files for Builds
Working with Multiple Projects
By default, projects are built such that all output files are created in a subdirectory of the project directory. The directory is named based on the build configuration (e.g. Debug or Release). In order for sibling projects to refer to each other, each project must explicitly add the other project output directories to their path in order for linking to succeed. This is done automatically when you set the project dependencies.
What's New in Visual C++ 2010, Project-to-Project Dependencies http://msdn.microsoft.com/en-us/library/dd465215(VS.100).aspx says:
"In earlier releases, you could define dependencies between projects that were stored in the solution file. When these solutions are converted to the new project file format, dependencies are converted to project-to-project references. This change can affect applications since the concepts of solution dependencies and project-to-project references are different."
Ok, but how are they different ? What do I have to do to get things working again?
I don't see any helpful documentation in
Can somebody point to the documentation that explains how one project will automatically link in the .lib output of another project ?
Or do I really have to put an entry for EACH CONFIGURATION for project | Properties | Configuration Properties | Linker | Additional dependencies ?
thanks in advance... Andrew
Wednesday, March 03, 2010 7:08 PMHi Andrew, to set project to project reference through UI, you can right click on the referencing project, choose "Reference.." from the context menu. On the property page that brought up, your lib project should be one of the projects that you can add reference to.
In this blog, I have a section explaining the changes in terms of project dependency and project to project reference.
Li Shao, MSFT
- Proposed As Answer by Andrew7Webb Wednesday, March 03, 2010 7:28 PM
Wednesday, March 03, 2010 8:04 PMThank you, I was mistakenly thinking that "references" only applied to C# stuff.
These directions solved the problem:
To establish a dependency on library project L from project P:
Right click on project P, select references.
Click on "Add New Reference", select library project L.
I have some suggestions:
0) Since a VS2008 solution already knows the project dependencies, why not let the the VS2010 solution conversion process build the project by project references for the user?
1) VS should be able to add a .props file to all projects in a solution.
2) VS should be able to create a .props file from the deprecated "Tools | Projects and Solutions | "VC++ Directories" entries. Then the user can use (1) to upgrade a whole solution with one command.
3) How about some visual indication to tell the user which projects in a solution failed ?
Or at least put the the project name on the "Build FAILED." compiler output line?
Wednesday, March 03, 2010 10:10 PM
for (0), yes, VS2010 conversion already doing that. If you have C++ project dependent on other project types, including C#/VB projects, project dependencies will be converted into Project to project reference. Below is one exception that I captured in the blog: http://blogs.msdn.com/vcblog/archive/2010/03/02/visual-studio-2010-c-project-upgrade-guide.aspx
-If you have a C# application that is dependent on a C++ application and this dependency is only expressed through solution dependency, the current conversion process won’t change the solution dependencies to the project to project references. You may run into build errors caused by incorrect build orders especially when building at the command line with MSBuild directly. To fix the issue, you will need to manually se up a proper project to project reference for C# and C++ applications.
For (1), Yes, VS has the ability to add .props file to all projects in a solution. Just open up property manager, multiselect all the projects and add new or existing .props files.
For (2) yes, we are already doing that. The props file are called microsoft.cpp.<Platform>.users.props.
VC++ Directories are no longer supported in VS2010 through Tools->Options page. Instead, VS2010 introduces the user settings file (Microsoft.cpp.<Platform>.users.props) to control global settings including Global search path. These files are located at $(USERPROFILE)\appdata\local\microsoft\msbuild\v4.0 directory. Upon migration to VS2010, the custom settings of VC++ Directories from VS2005 or VS2008 are migrated to these user files. These global settings files are imported into all the converted and newly created projects.
For (3), that is a good suggestion. Please open a bubg through connect: http://connect.microsoft.com/VisualStudio/content/content.aspx?ContentID=12362 or please let me know if you would like me to open the bug instead.
Li Shao, Project and Build Team
Thursday, March 04, 2010 9:37 PM
Hopefully the documentation will be updated to reflect the information discusssed. Thanks again, Andrew
Friday, March 05, 2010 12:12 AM
Thank you for providing the suggestion and opening the bug, Andrew!
Li Shao, MSFT
Monday, April 26, 2010 5:28 PM
Regarding this document and the "project-to-project" dependencies, it is state that :
"First, user can build a project without the solution and the dependent projects will be built automatically. Second, it sets up the customer for large trees, where they might not use solution files. "
It seems pretty clear that solution file is not necessary. I doesn't work for me. I hope you can enlighten me. Here is what I do. It is my first steps with VS2010 (upgrading from VS 2005) :
- I converted all *.vcproj to *.vcxproj with vsupgrade.exe.
- For a small Unit Test application, a basic and simple C++ application :
- Added the project app vcxproj to a new solution
- Added a vcxproj of a static library to the solution. It's already strange I have to do that. I do this in order to add the library vcxproj as a reference of the app. I was not able of doing this without first add the project to the solution. But I was still happy to be able to add the lib project as reference to the app.
- I build once and both projects build. (both projects in solution)
- I removed the lib project from the solution.
- The reference disappears. If I build again, only the app builds.
The point is, solution are necessary or not?
Monday, April 26, 2010 7:20 PM
Yes, solution files are not necessary if the project reference information is present in the project.
Regarding 1, if you go through my blog: http://blogs.msdn.com/vcblog/archive/2010/03/25/to-the-command-line-enthusiasts-some-quick-know-hows-for-upgrading-to-vs-2010.aspx, I have mentioned that VCUpgrade.exe has some limitations and cannot be used to convert solution files. It is recommended only for single project files: those which do not contain project to project references, and whose solution files do not contain project dependencies as this information from the solution will be lost during conversion.
Regarding 2, when you removed the lib project from the solution (I assume you did it from the IDE), the reference information from the project got removed as well (just the way it got added when you included the library project as a reference to the app). This is why only the app was building when you tried building again.
The right way for you to do it is to close the IDE and then deleting the solution file from Windows Explorer, so the reference information still remains in the project. An easy way to rebuild your project would be through the command prompt using the MSBuild command, something like "msbuild /t:rebuild <ProjectName.vcxproj>". This will rebuild both the projects. However, if you try opening the project from the IDE (DevEnv.exe), it will open up only your app project as there is no solution file for it to refer to and realize that it needs to open up the library project as well. Hence when you do a "Build Solution", given the solution contains only the app project, the build would fail complaining that it cannot find the .lib file.
Renin John Visual C++ Project & Build Team
Wednesday, April 28, 2010 4:37 PM
Thank you for the quick answer,
I was envisaging that workaround. I'm not considering it "a solution" for this reason : We are about 30 developers here, each one having its own solutions. We don't share solutions via CVS. What I can think of this is, as soon as a developer will remove a project from its solution, we'll loose the dependency. Is this right?
May be we don't have the right setup. I'm the one in the company who had setup scripts to generate solutions. We scan *.vcproj to find "additional dependencies" on libraries (static ou dynamic). We built solution files based on the scanning. We resolved dependency by figuring which project produces a lib needed by another project.
Example : AppA.exe built by project AppA.vcproj links with LibA.lib. Base on my scan, I had a little database and I know that LibA.vcproj produces LibA.lib. Therefore, I had a dependency between AppA.vcproj and LibA.vcproj in a solution file.
I was pretty enthusiast when I read that dependencies are saved in project files (vcxproj). But now, I'm now pretty disappointed. I can't figure out how to throw all those scripts, which I have to port to VS2010 now, to the garbage can.
Could you realize that we have a little GUI app to built with a proper management of dependencies? Isn't the role of an IDE as expansive as Visual Studio to do this?
Should we put solution files under CVS? What is the best way to manage dependencies with Visual Studio?
By the way, we really appreciate your help and your blogs (including Li Shao). I think your support team should develop and design a little bit more :)
Wednesday, April 28, 2010 9:13 PM
Moving dependency information into project files is the direction we are going. For this release, however, solution files are still useful. I would recommend your developers to check-in their solution files.
If you convert your application from previous version, solution dependencies will be moved to project to project references. For new projects that are added, please use project to project reference to set dependencies. Yes, this may mean that you have to change your script to modify the project files instead of the solution files.
Currently, Visual Studio does not have the capability to automatically scan for dependencies. This would be a good feature for us to consider.
Hope this answers your question to some extend.
Li Shao, MSFT
Wednesday, April 28, 2010 9:27 PM
Also, to be clear, if you use IDE or Devenv /upgrade <solution> to do the conversion, solution dependencies will be converted into project to project reference. VCUpgrade.exe is designed for converting single project without dependencies.
Li Shao, MSFT
Thursday, April 29, 2010 3:29 PM
Thank you very much for those quick, honest and complete answers.
In the name of InnovMetric's Dev Team.