Code Heavily Dysfunctional Due to Circular Dependencies and Linking Issues. [Help]

Hello all,

I somewhat figured this would happen eventually. Because I am entirely self-taught in terms of programming, I have often missed key strategies with using different languages. C++ is no exception. I have been coding away for days now and things have been going smooth, but yesterday I hit upon an error message that I just couldn’t figure out. (it was an LNK2019 Message). I scoured my code to try to find any issues, and was unable to do so. Commenting out code didn’t seem to help, and my big problem at this point is organization. I could really use some help here from a fairly experienced programmer. My code is throwing a lot of circular dependency errors, and I understand that this is due to “circular” includes, but honestly I haven’t been able to resolve the issue using Forward Class Declarations. I could really use help reorganizing my code in a way that makes sense given its intended function, however, I am having a hard time finding resources that make sense to me (as there are some terms that I am not as familiar with as a seasoned programmer. Would anyone be willing to discuss this and look at my code via email or skype? I don’t really want to post it to the forums due to size and extent. I am fairly sure that for someone with more C++ experience this is likely not a serious problem, but I’m lost… and somewhat in need of emergency help, as I can no longer understand the compiler errors that I’m getting.

I’d appreciate any help I can get on this.

I’m by no means an expert, but I was having the same issue recently. Luckily we have a good tech-support guy to help us out with things like this. As a bit of background, the C++ compiler breaks up the code into ‘modules’ which it compiles separately, then links them all together at the end. The reason you get link errors is because your code compiles, but the compiler can’t put it together due to the way it’s written.

If you know where the circular dependency is occurring, you can possibly get around it one of two ways. Firstly, you can try only including header files that you need in the .CPP file and not the header file, this usually works but of course the more headers you add to your code, the longer it will take to compile. The other method, is to actually create a class within another classes .cpp file, which basically tells the compiler ‘here’s a class that this class is going to reference, but I’m going to fill in the data about it somewhere else’. That way when the compiler puts everything together, it’ll fill in the blanks and your code will still work.

I haven’t got my work-code to hand right now, but when I get back I may be able to come back and post an example unless someone beats me to it.

I didn’t read your whole message but for Circular Dependencies go through this A new, community-hosted Unreal Engine Wiki - Announcements and Releases - Unreal Engine Forums

Hi ,
I’d be happy to help. Perhaps the best way is to pick one case of a circular dependency that you have and post it here. Often circular dependencies can be resolved by re-thinking your architecture a little bit.