Adding a new CPP file to project causes other classes to be undefined
I have no idea what's happening anymore. I've tried everything I can think of with no luck. I have been trying to add a new class to my existing project but every time I try to compile it in visual studio, I get 100+ compiler errors which have nothing to do with the class I just added.
Environment: Visual Studio Community Edition 2013 Engine: UE 4.6.1 Source control: Perforce OS: Windows 7 64 bit
Control Scenario 1: I compile my project with my existing classes. Result: Everything compiles successfully and the editor opens.
Scenario 2: I add a brand new header file and do not declare anything. Result: Everything compiles successfully and the editor opens
Scenario 3: I create a bare essentials CPP file to go with the header file. Result: The compile fails. There are no errors in my code. One of my other classes is now unrecognized and that's causing 100+ errors (not linker errors). Removing the newly added CPP file causes the errors to go away, so there's some sort of relationship going on here.
Scenario 4: I just create a new blank CPP file with no header file. The only line it has: #include "[projectname].h" Result: Same as scenario #3.
Scenario 5: I create a brand new project and add a new header and CPP file, just like I do in Scenario 3 &4 Result: Compiles with no issues. Therefore, its project specific.
I tried adding the class through both the editor and manually through visual studio. Both cause the same results.
What I've tried:
I've added dozens of sources files to the project in the past and none of those have caused any issues. It seems that this started happening recently after I submitted my last build to source control. I tried checking out all of my files just in case there was some write protection issues, but that made no change.
Why would my code compile with no issues, but adding a blank CPP file to the project causes it to break? All I can think is that somewhere, the generated code is getting messed up by a new CPP file and I don't know where its happening or how to fix it.
Header file: "TestClass.h"
CPP File: "AnyName.cpp"
asked Feb 03 '15 at 08:55 PM in Bug Reports
After lots of rigorous testing over two days, I have discovered the following:
Root cause of my issue: I had two project header files. #1 was "[projectname].h" and located at "/[projectname]/source/[projectname]/[projectname].h" #2 was also "[projectname].h" and located at "/[projectname]/source/[projectname]/public/[projectname.h]"
Each header file was different (I forgot to delete one a long time ago).
Oddly, this didn't raise any errors. However, it did cause some really weird behaviors which are as follows: If I had 29 CPP files in my project, the UBT would successfully build the whole project. It didn't matter what kind of CPP files they were. At one point, I backed up and deleted all of my source code and created 100+ empty CPP/H files via a script to see if something else was going on. Through empirical testing, I found that the 30th class always caused a series of build errors. The class code was irrelevant. It appeared as if the CPP files could no longer find their associated .H files. Yet, removing one class seemed to fix the issue. However, there's no way you can work with a fixed limit on classes.
For some unknown reason (unknown to me anyways), the UBT would seem to "overflow" or something when there were too many classes and it would send the overflowing classes to my other header file which wasn't including [projectname]Classes.h. This caused the CPP files to not know about their header files, and everything suddenly and mysteriously looks like the header file is missing.
Solution: Look for duplicate [ProjectName].h header files in all of your source code folders and subfolders and delete them. The "pragma once" preprocessor directive won't help you here.
answered Feb 05 '15 at 04:38 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here