title: Setting up subproject in Microsoft Visual Studio 2010
body: <p>I am developing Windows code in C using Visual Studio 2010.</p>
  
  <p>I am working on several related projects: a static library, a DLL, and an executable.  The DLL should have the static library linked in, and the executable depends on the DLL.  (I am using "implicit" DLL linking; I do not need to control the DLL loading and unloading.)</p>
  
  <p>Right now I have three separate VS2010 projects, but I know it is possible to set things up as "subprojects": the static library should be a subproject of the DLL, and the DLL should be a subproject of the EXE.</p>
  
  <p>I want to solve the following:</p>
  
  <ul>
  <li><p>When I rebuild the EXE, it should rebuild the DLL if need be, and in turn the DLL build should rebuild the static library if need be.  I'd like to just have the EXE open, hit the <code>F7</code> key, and everything builds.</p></li>
  <li><p>When I rebuild the EXE as Debug, it should link with the Debug <code>.lib</code> file from the DLL; likewise when I rebuild the EXE as Release, it should link with the Release <code>.lib</code> file from the DLL.  If I set up the subprojects correctly, will this Just Work automatically?</p></li>
  </ul>
  
  <p>EDIT: I have made progress.  First, in the DLL project, I used <code>File / Add</code> and then chose <code>Add Existing Project</code> to add the static library.  (This is only available on the <code>File</code> menu as far as I can tell!  It definitely is not in the right-click menu.)  Second, I clicked on the DLL project in the "Solution Explorer" sidebar on the left, then right-clicked and chose <code>Project Dependencies...</code> and set that the DLL project depends on the static library project, which should build first.  Visual Studio seems to have then magically set up the link dependency for me, and when I hit the <code>F7</code> key in the DLL project, it will build the static library project.</p>
  
  <p>I tried repeating the above steps for the EXE project.  Now it will build the DLL, but it isn't linking things correctly yet; the linker is complaining that the functions exported from the DLL are not available.</p>