I created a new project, and Added Existing Files: a certain .h and .cpp pair that I wanted to reuse.

For some reason, when compiling the new project, I get an error coming from Main.obj, stating that I am missing a certain include file - a file that is referenced in the main.cpp of the original project but definitely not in mine.

Both projects are doing Shadow Build, to different locations (in both cases, not to a folder on the level of the project folders but to another location).

I managed to reproduce this at least once with two new projects, one including a shared file from another. When I made sure that the original project's main was using something that the new project's main didn't have - I got the error.

First off, I am working with the projects separately, right now only with the second one - the one that gives me the error.

Second, I don't even have an #include statement. All I did was to add the existing files into the project, without actually including any in my actual code.

I have a feeling like there's an old Main.obj file somewhere that is somehow made based on my first project, and anything I do with the second project is working with it - but I'm not sure how to get to the actual evidence/solution.

Hmm... Those are pretty edited pro files so I don't see anything wrong there.

How about try building just application 2 on the command line. Take Qt Creator out of the equation and do qmake/make on the command line. For mingw it would be:

qmake

mingw32-make

For MSVC, you would need a dev env command prompt:

qmake

nmake

In your first post you mentioned that the main.obj file referenced in the temp directory didn't exist. That means that it was built for that run. This means that it is using the code from main.cpp for app1 instead of app2. This means you more than likely have some kind of build issue that I can't see since I can't see Qt creator/real project files/or code. For some reason Qt Creator is choosing to build App1's main.cpp instead of app2's.

So test command line and see if it resolves, and then maybe you just need to delete your app.pro.user and start it over from the base pro file.

Sorry I can't help more, there just isn't enough information for me to see anything.

Anyway, I think I see the problem. When you specify the build directory the paths being set in the resulting makefile are causing main.cpp to be made into main.obj including the one in FirstApp.

Because the makefile is using object matching instead of specifying the files to build specifically it is getting confused. So it is building main.cpp from FirstApp after it builds it from SecondApp. This results in main.obj being the one from FirstApp as it overwrote the one from SecondApp.

There are a few solutions I would use for this:

Since you have an object you need in multiple projects consider making it a simple library with that object and any others you share. Then you can have each app include that lib and you're all set. No conflicts. Plus this has the added benefit of centralized code for that object without the confusion of code shared between applications.

Copy the "shared" code to the second app. You won't really be sharing here so any changes would have to be done in both copies of it. This is a hacky solution. #1 is much better idea for this.

You can try not specifying build directory on the command line but instead putting it into the project files, things like:

Using this approach I would put in checks for debug versus release and name directories and stuff appropriately.

Anyway, I would honestly move to the library approach. Not only will it fix your problem but it is a much cleaner way to share code between applications. Much easier for maintenance too when someone other than you comes along to support the app. Or even you in the future if you forget that you are sharing code and such.

I agree that the library approach is best - in fact that would be the longer term goal. But isn't the problem here the paths and the identical filenames? Meaning, if I had the same output directory, and a file named ClassA.cpp in both my new project and in the other project (regardless of whether it is a library or an application) - wouldn't I get the same issue with the .obj of this file?

I think for now I will either try your suggestion #3, or stick to my very basic workaround: just making sure my new project doesn't use the same filenames as the existing one (i.e. replacing main.cpp with mymain.cpp).

I think I can mark this one as SOLVED - but I wonder, if I really manage to reproduce it another time with another minimal project - maybe this qualifies as a QMAKE bug.

Yea the problem is the makefile. I'm not sure I would blame qt because it's more of a make issue. When qt generates the makefile they are using @<< and $< for matching of objects to build. So in the implicit rules the make file builds any cpp file that it finds in the directory matching the pattern.

So since it knows it needs to build main.cpp when it sees it in 2nd app dir it builds it. And when it sees it again in 1st app dir it builds it again overwriting the one you actually wanted.

This is what looks like is happening. I'm not 100% sure but that is how I'm reading those makefiles. Been a really long time since I wrote my own makefile though. :-)