Linker Error

When the FBullCowGame BCGame; is above int main () in the main.cpp I get: 1>LINK : fatal error LNK1104: cannot open file ‘f:\documents\visual studio 2015\Projects\UnrealCourse\Debug\BullCowGame.exe’

But, when I put the same thing inside of a function it compiles and runs fine. I’ve even ensured the files are the same from GitHub. I’m running VS Community 2015 Update 3. Any ideas? Thanks.

Linker errors usually have to do with stuff like that not having a reference to something.

In this case, main.cpp might not have a reference to FBullCowGame, the type.

Where you have the #includes in the top, do you have #include “FBullCowGame.h”? If not, that is your problem.

Another possible issue is the ordering of the #includes up top. Make sure that the #include I told you about is the last one to be included. This is actually a bad dependency to have, but Ben covers how to fix it in the Battle Tank section.

I copied the actual files… Also, when I instantiate the bullcow game INSIDE a function I get no linker error… its only when I move it to the top of the file. Did you happen to read my original post? If the include files were not in the right order why then would it work inside of a function? I also said that I ensured that the files were the same as on Github. I do appreciate responses here, but PLEASE make them useful.

Can you post a screenshot of your main.cpp in here?

Had the same linker error.
It was because I left opened window with the game from previous build. Window was minimized and I didn’t notice it.
After closing the window project built successfully.

I am also having this error. The following are screenshots of my main, cpp, header, and the exact errors I am recieving. Also, I am using VS 2017 and noticed when I created my header file, it auto created the namespaces? at the bottom. I added a comment to the code to denote them. Also, whenever I tried to create the cpp, it kept trying to create it inline, instead of in a new cpp file.

The problem is in the header file. Never define functions in header files! Remove everything after line 22, and it should work.

1 Like

Privacy & Terms