4

I have a solution with two C++ (CLR) projects. One project references the other, so the Project Dependencies and Build Order correctly reflect that. Both projects target the same output folder. The dependent project has the dependency configured with Copy Local: false.

If I "Rebuild" the dependency by itself, it builds fine and its targets are in the output directory.

When I "Rebuild" the solution (or the dependent project), I get:

error LNK1181: cannot open input file '<outdir>\Dependency.lib'

Sure enough, the dependency outputs are gone from the output directory. If I look at the build log, the dependency seemed to have (re)built correctly, but then those outputs seem to have been deleted as soon as the dependent project build started. Why would that happen?

Additionally, when I "Clean" the solution, then immediately "Build" the solution, I don't get any errors.

Isn't "Rebuild" supposed to be, effectively, Clean + Build?

lesscode
  • 6,221
  • 30
  • 58

2 Answers2

1

A rebuild in Visual Studio cleans and builds the projects one by one, so what probably ends up happening is

  • Project A is cleaned.
  • Project A is compiled.
  • Project B is cleaned, removing parts of the output from Project A due to the same output directory.
  • Project B fails building due to missing dependencies.

More discussion here.

Community
  • 1
  • 1
Joachim Isaksson
  • 176,943
  • 25
  • 281
  • 294
  • Makes sense, I guess. Although that's not how it works for a similar solution with two C# projects... – lesscode Aug 28 '12 at 18:07
1

The second project is deleting anything from its output directory when you perform a rebuild on it. Cleaning does not discriminate between files that are bonafide project output, and other files. Clean All followed by Build All doesn't cause it because there is no cleaning of the output folder between building of the projects. In short, Visual Studio doesn't support multiple projects outputting to the same folder. Output them to their default locations, and then let Visual Studio copy dependencies as it was intended/designed to do.

Brent
  • 4,153
  • 4
  • 30
  • 63
  • Right. I was confused because we've had a solution with ~100 C# projects - all outputting to the same bin folder - working just fine for a while now, so I think this is a C++ limitation rather than a Visual Studio one. – lesscode Aug 28 '12 at 18:14