Placement of cpp code

When entering the code for this lecture I initially placed it in the projects directory I created for the hello.cpp. However when I came to run the code using debugger it failed to compile, with the output in the picture below. I had to move the cpp file to the raylib vs-code directory in order to get a compile and run.

I received the same error, but moving my file into that directory didn’t help. Even my installation of the workspace folder didn’t go as it did in the video. Does anyone have any insight on this error? Thanks!

FINAL EDIT:
I FOUND THE SOLUTION!

TLDR: You need to make your .cpp file in the same directory as the vscode-template stuff!

I think between videos, Stephen either renamed the folder after getting it from the git repository, or made a copy of it and renamed that. Not sure which he did, but he never shown that he did in the video. Took me awhile to realize when he was creating his hello.cpp and axe-game.cpp files that the file explorer had a “.vscode” folder. That’s because it was in that same directory. Recreated axe-game.cpp after opening up the workspace, then debugged it. Worked like a charm. Screenshot follows of my file explorer:

Just as a test, I also started fresh, made a copy of the “vscode-template” folder, renamed it and re-coded axe-game.cpp in the copy to see if it would still compile. It compiled just fine. I’d recommend keeping the template untouched and just make a new copy of it that is named something more relevant to the project.

Original post content follows for forum historical integrity:

Also getting this. Tried going back through the videos to figure out what was up, but can’t seem to find a solution… Looking for answers as well.

EDIT 1: As a test, I opened the VSCode sample in the Raylib directory and tried to debug with the default build task supplied with the sample project. Or so I thought… First time was a fail, but then I realized I was trying to “compile” the build file instead of main. Went back to the sample’s main.cpp and tried again. Worked flawlessly. Going to attempt with this exercise. Will post results.

EDIT 2: Nope… Going to try something… Wacky. Maybe copy over the makefile and stuff from the Raylib example project and try that…

EDIT 3: Didn’t work either…

3 Likes

You’re the man, JohnnyThreeDee! Thank you for this solution because this put a serious damper on my course progress. I hope there aren’t anymore huge roadblocks going further, but collectively I think we can get past them. Thanks again!

1 Like

Moving the axe_game.cpp back to the template folder sort of worked, but I got a different error.

Looks like it isn’t finding the header or the raylib library. Here’s my code:

#include “raylib.h”

int main()

{

InitWindow(640, 480, "Hello");

}

Any help?

1 Like

So, changing the name of the source file to axe_game.c let me compile and link. Hmph.

Looking for places in the makefile I need to change from .c to .cpp to compile as c++. Little lost, but still digging.

Larry

1 Like

Odd… If it’s compiling with a .c file, it should work with a .cpp file as well… Silly question, but did you open the workspace in the template folder and add axe_game.cpp to the workspace before compiling?

Yep, I sure did. However, I found a line in the tasks.json file under windows | args that was:

“OBJS=${fileBasenameNoExtension}.c”

I changed it to:

“OBJS=${fileBasenameNoExtension}.cpp”

and it compiled. I’m not sure why it works for everyone else without modification, but not for me. Perhaps I screwed something else up while I was poking around. Anyway, for the moment, I can compile. (But I can no longer compile .c files LOL. Only .cpp). I think there must be a better solution!

1 Like

Hey, if it works, roll with it lol.

Thanks for adding to the solution!

I too have the exact same error when I try to build i.e Run Build Task (Ctrl+Shift+B) on Windows.

Starting build…
C:\raylib\mingw\bin\g++.exe -g D:\VidProjects\CPlusPlus_Projects\GameDev\Project\axe_game.cpp -o D:\VidProjects\CPlusPlus_Projects\GameDev\Project\axe_game.exe
C:\WINDOWS\TEMP\ccoVJGeB.o: In function main': D:/VidProjects/CPlusPlus_Projects/GameDev/Project/axe_game.cpp:13: undefined reference to InitWindow’
collect2.exe: error: ld returned 1 exit status

However, if I Start Debugging (F5), the program runs perfectly fine and the window is displayed.

Not sure what is causing this issue

Hi there, for those who are struggling to build outside of using Start Debugging (F5), can you give this a try? Just focus on step 4, every other step can be skipped as they should already be completed via the template or through lectures up to this point.