Issues when I am trying to build and run my code

I’m not able to run the starting code of the course, after I included the raylib.h file to my axe_game.cpp:
MY CODE:

#include <stdio.h>
#include "raylib.h"

int main(){
    printf("Leo");
    InitWindow(350, 200, "Leo");
}

TERMINAL OUTPUT (when i try to debug and run):
Starting build…
/usr/bin/g++ -fdiagnostics-color=always -g /home/hala/Documenti/GitHub/axe_game/main.cpp -o /home/hala/Documenti/GitHub/axe_game/main
/usr/bin/ld: /tmp/cciViunJ.o: in function main': /home/hala/Documenti/GitHub/axe_game/main.cpp:6:(.text+0x31): undefined reference to InitWindow’
collect2: error: ld returned 1 exit status

Build finished with error(s).

  • The terminal process failed to launch (exit code: -1).
  • Terminal will be reused by tasks, press any key to close it.

I tryed several things, but this issue remains

The issue is not with your code, it is with the compiler. A similar thing happened with me in another course, I had to delete some file in a compiler folder to fix it. It can also happen if you have an old version of a compiler.

I even try to build raylib as a shared library, but I had the same issue.
Idk, if this could help:
I’m using Ubuntu 24.04 lts
and if I build from terminal using this line:
cc main.cpp -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
I’m able to execute the code from the file created…
but I’m not able to debug and run from Vs Code

This tells me that VS Code can find raylib.h but the compiler cannot. Since you’re using Ubuntu, can you tell me how you installed Raylib?

First of all I tryed to install raylib from Homebrew, and it gave me this error, then I found a post where a teaching assistant suggests to try to install, from the raylib github official repo, a shared library because the error could be caused by old version of the static lib, and I tryied , but nothing is changed.
both with ur template as in a new project where I copy pasted the raylib.h file and the library file.

edit:
I tryed to compile from terminal with g++ and gcc, but both the compiler gives me the same error:

main.cpp:(.text+0x22): undefined reference to `InitWindow’

edit2:
The only way to compile succesfully, even using the terminal is by execute this command:
gcc <name_of_file_to_compile> -o <name_of_the_output_file> -lraylib -lGL -lm -lpthread -ldl -lrt -lX11

The first edit makes sense because gcc wont know of the existence of raylib or where it is without linking. Though I’m glad the second option worked.

Though I am curious… what happens if you type “brew --cellar raylib” in your terminal?

If I type “brew --cellar raylib”:

/home/linuxbrew/.linuxbrew/Cellar/raylib

Hmmm. On our template, if you tried adding that path to the “include path” section of c_cpp_properties.json file for Linux, what would the outcome be?

If i include this path the debug seems to work fine…it gives some warning during the build, but now i can debug and run using VsCode :triumph:

Awesome! I’m glad that helped resolve the issue. Warnings can usually be ignored, though if you let me know what it is I may be able to help clear that as well.

Just wanted to bump in because I’ve been getting pretty much the same error for the past 6ish months on Windows.

-1

There should be a “build debug” and/or “build release” option when choosing your build task. That option is not going to know that Raylib exists on your system or where to find it.

Huh, I’m not really getting any options so I’m not sure what you mean by that.
By looking around I discovered that if I go to “Run” and “Start Debugging” or F5 the project builds and runs without a problem. It’s only when I press the “debug arrow” in top right that I get the error. Kinda baffling, it never occurred to me that there could be any difference between the former and the latter.

For me, it seems to work best when I “prime” vs-code by Selecting Terminal > Run Task, then picking build debug. Then F5 and the debug arrow seem to behave themselves.

But also, VSCode is a weird program that I argue is probably trying to do too much. But that’s just my opinion :wink:

I tried it and it didn’t help :no_mouth:
Debug arrow still throws that error but F5 and dropdown option builds normally lol.
This a real WTF moment if I’m being honest, but hey, I’m glad I discovered by accident that I can actually build my project. For the past 6 months I was under the impression that it was hopeless, I even reinstalled my whole system just to do a complete fresh install of raylib and VS code BECAUSE I THOUGH THE GOD DAMN DEBUG ARROW DOES THE SAME THING THE F5 AND DROPDOWN OPTIONS DO :man_facepalming: :man_facepalming: :man_facepalming: :man_facepalming: :man_facepalming: :man_facepalming: :man_facepalming: :man_facepalming: :man_facepalming: :man_facepalming: :man_facepalming: :clown_face: :clown_face: :clown_face: :clown_face:
Apologies, I lost my cool a little there.

1 Like

No worries! Programming can be quite frustrating at times, for sure.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms