DEV Community

Mytx
Mytx

Posted on • Edited on

De[v]log#4: Raylib setup on vscode

Image description

Install Vscode __https://code.visualstudio.com/download
Install Raylib __https://github.com/raysan5/raylib/wik

Image description

You don't need to include library path if you are on linux environment but you need to do the following if you are working with windows

C:\raylib\w64devkit\bin

On window raylib installer will install everything on C: like above
Copy that and put that in Environment Path

Control Panel -> Edit the system environment variables -> Environment Variables -> System Variable -> Path -> New -> C:\raylib\w64devkit\bin -> Ok All

With that you are set for compilation...

Before compiling anything you need to fix something upfront tho...

#include "C:/raylib/raylib/src/raylib.h"
#include "C:/raylib/raylib/src/raymath.h"
Enter fullscreen mode Exit fullscreen mode

You need to declare raylib headers like this...since raylib library and headers are not in default include paths on window...you dont need to do this part for linux tho

Image description

Compiling on Command Line Interface:

For Window
gcc core_basic_window.c -lraylib -lopengl32 -lgdi32 -lwinmm -o core_basic_window.exe

For Linux
cc main.c -lraylib -lGL -lm -lpthread -ldl -lrt -lX11 -o main

This is a simple command line to compile raylib source_code written in C (just change gcc to g++ for C++ codes)

Navigate to your source code file from command line using
cd C:/directory and run the command line to compile the code

After that: double click core_basic_window.exe on window (You can run ./core_basic_window.exe if you are on powershell) or run ./main with terminal on linux

Compiling on vscode

Now to compile and run the code in vscode...copy and paste the following in the task.json ( Ctrl+P -> task.json to open the file to edit)


{
    "tasks": [
        {
            "type": "cppbuild",
            "label": "C/C++: g++.exe build active file",
            "command": "C:\\raylib\\w64devkit\\bin\\g++.exe",
            "args": [
                "-fdiagnostics-color=always",
                "-g",
                "${file}",
                "-ID:\\C:\\raylib\\raylib\\src",
                "-L:\\C:\\raylib\\raylib\\src",
                "-lraylib", "-lopengl32", "-lgdi32", "-lwinmm",
                "-v",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.exe"
            ],
            "options": {
                "cwd": "${fileDirname}"
            },
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "detail": "Task generated by Debugger."
        }
    ],
    "version": "2.0.0"
}

Enter fullscreen mode Exit fullscreen mode

If directory locations are mismatch...try to fix that

<<<>>>

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "C://raylib/raylib/src"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.22000.0",
            "compilerPath": "cl.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "windows-msvc-x64"
        }
    ],
    "version": 4
}
Enter fullscreen mode Exit fullscreen mode

Changing "c_cpp_properties.json" to this will save you the trouble from typing -> #include "C:/raylib/raylib/src/raylib.h"...
with that...now you only need to type #include "raylib.h" everytime you write a new source

Image description

Top comments (0)