4

I am a beginner at c++ and I would like to use raylib with vscode instead of using notpad++. does anybody know how to add raylib to vscode.

josephi
  • 81
  • 1
  • 1
  • 5

2 Answers2

8

Here is the official guide on this topic : Using raylib in VSCode.


I am re-writing the instructions mentioned in the link (in simplified form) :

  1. Install Raylib from the official release binaries (Install using raylib_installer_v300.mingw.exe on Windows).

  2. Install VSCode.

  3. Now create a folder (say my_project) in which you want to keep the files of your project.

  4. Download files from this link and copy them into the folder you made at above step.


This should result in the following structure :

my_project
 |- .vscode
 |    |- c_cpp_properties.json
 |    |- launch.json
 |    |- settings.json
 |    |- tasks.json
 |- Makefile
 |- Makefile.Android
 |- main.c
 |- main.code-workspace

  1. Modify the paths inside in the files if gcc.exe is not there in C:/raylib/mingw/bin/.

  2. Install C/C++ for Visual Studio Code Extension.

  3. Then open VSCode in the folder you made (right-click on folder and open with VSCode).

  4. Open main.c file, press press F5. Your code should compile and run on debug mode.


If you face any problem in following the step by step instructions then please add a comment.

brc-dd
  • 10,788
  • 3
  • 47
  • 67
  • I can't get it to work so I will just use the IDE that Raylib comes with but thank you anyways – josephi Sep 08 '20 at 11:14
  • @josephi Can you tell me any specific problem that's occurring to you during the setup? – brc-dd Sep 08 '20 at 11:15
  • when I put all the files in the folder they don't show up in vscode – josephi Sep 08 '20 at 12:03
  • 1
    @josephi Are you sure you are opening the whole folder and not just a file? Open VSCode and press `Ctrl + K` followed by `Ctrl + O`. Then choose the `my_project` folder to open. It will open the workspace for you. There on left side you must see `.vscode` folder and `main.c` files. – brc-dd Sep 08 '20 at 12:22
  • @brc-dd Could you elaborate more about Step 1? I downloaded the raylib file (`raylib-4.2.0_win64_mingw-w64.zip` in my case) but I'm not sure how to install it. Where do you find `raylib_installer_v300.mingw.exe` and how do you use it to install the raylib file? – Ogiad Nov 04 '22 at 22:32
  • 1
    @Ogiad Check the releases, there will be a file named `raylib_installer_vXXX.mingw.exe`. (version will be different depending on the release). – brc-dd Nov 05 '22 at 03:17
  • 1
    Try adding C:\raylib\w64devkit\bin to your PATH environment variable and then restart whichever terminal you're using. This did the trick for me. – Nick Nov 10 '22 at 14:19
  • @brc-dd, Thanks to your help, I can now run the example code (rotating cube) with F5 key. However, when I try to compile the code with 'Run code' , I get an error message saying "fatal error: raylib.h: No such file or directory" – Ogiad Nov 10 '22 at 20:07
0

The most straightforward approach to start using raylib in Visual Studio Code is to download a pre-configured template.

If you have raylib installed in the default directory on the C drive (C:\raylib), this template should work seamlessly without any additional modifications.

https://github.com/educ8s/Raylib-CPP-Starter-Template-for-VSCODE

To get started, simply download the raylib template and double-click on the main.code-workspace file. This will open Visual Studio Code with the project loaded.

In addition, make sure you have the C++ extension installed in Visual Studio Code.

Press F5 on your keyboard and you should see a bouncing ball example.

Nick
  • 1,393
  • 1
  • 14
  • 22