0

Greetings

I'm very new to C. I would like to know the most minimal amount of steps/code for making a basic window using raylib. I'm using Linux and have followed the steps on github https://github.com/raysan5/raylib/wiki/Working-on-GNU-Linux, but I honestly don't know where to begin to build my own project. Is cmake or make required for a basic window like in the example: core_basic_window.c, that I'm able to compile (using the instructions from github, but I'm not sure how to modify/simply the code for my own project). Thank you : )

I've tried to copy and past this code from the github pull/project/directory and run gcc on it but I get error messages:

// Filename: core_basic_window.c

#include "raylib.h"

int main(void)
{
    // Initialization
    //--------------------------------------------------------------------------------------
    const int screenWidth = 800;
    const int screenHeight = 450;
 
    InitWindow(screenWidth, screenHeight, "raylib [core] example - basic window");
 
    SetTargetFPS(60);               // Set our game to run at 60 frames-per-second
    //--------------------------------------------------------------------------------------
 
    // Main game loop
    while (!WindowShouldClose())    // Detect window close button or ESC key
    {
        // Update
        //----------------------------------------------------------------------------------
        // TODO: Update your variables here
        //----------------------------------------------------------------------------------
 
        // Draw
        //----------------------------------------------------------------------------------
        BeginDrawing();
 
            ClearBackground(RAYWHITE);
 
            DrawText("Congrats! You created your first window!", 190, 200, 20, LIGHTGRAY);
 
        EndDrawing();
        //----------------------------------------------------------------------------------
    }
 
    // De-Initialization
    //--------------------------------------------------------------------------------------
    CloseWindow();        // Close window and OpenGL context
    //--------------------------------------------------------------------------------------
 
    return 0;
}

Couldn't compile:

########-ThinkPad-T430:~/Documents/c/bin/tmp$ gcc core_basic_window.c
/usr/bin/ld: /tmp/ccB5BYug.o: in function `main':
blah.c:(.text+0x2d): undefined reference to `InitWindow'
/usr/bin/ld: blah.c:(.text+0x37): undefined reference to `SetTargetFPS'
/usr/bin/ld: blah.c:(.text+0x3e): undefined reference to `BeginDrawing'
/usr/bin/ld: blah.c:(.text+0x65): undefined reference to `ClearBackground'
/usr/bin/ld: blah.c:(.text+0xa6): undefined reference to `DrawText'
/usr/bin/ld: blah.c:(.text+0xab): undefined reference to `EndDrawing'
/usr/bin/ld: blah.c:(.text+0xb0): undefined reference to `WindowShouldClose'
/usr/bin/ld: blah.c:(.text+0xbc): undefined reference to `CloseWindow'
collect2: error: ld returned 1 exit status

1 Answers1

0

You didn't like your libraries right. If you are using the Notepad++ option then: Create a Folder, and create a main.cpp/.c file. -> Navigate to the Raylib download folder, extracted of course, and click npp->then click notepad++.exe In notepad++ click file->Open (or Ctrl-O) then navigate to the folder you created for your project-> Write code then click F6 to run. That should be simple to follow instructions.

Compiler Flags (for GCC)

echo > Setup required Environment
echo -------------------------------------
SET RAYLIB_PATH=C:\raylib\raylib
SET COMPILER_PATH=C:\raylib\w64devkit\bin
ENV_SET PATH=$(COMPILER_PATH)
SET CC=gcc
SET CFLAGS=$(RAYLIB_PATH)\src\raylib.rc.data -s -static -Os -std=c99 -Wall -I$(RAYLIB_PATH)\src -Iexternal -DPLATFORM_DESKTOP
SET LDFLAGS=-lraylib -lopengl32 -lgdi32 -lwinmm
cd $(CURRENT_DIRECTORY)
echo
echo > Clean latest build
echo ------------------------
cmd /c IF EXIST $(NAME_PART).exe del /F $(NAME_PART).exe
echo
echo > Saving Current File
echo -------------------------
npp_save
echo
echo > Compile program
echo -----------------------
$(CC) -o $(NAME_PART).exe $(FILE_NAME) $(CFLAGS) $(LDFLAGS)
echo
echo > Reset Environment
echo --------------------------
ENV_UNSET PATH
echo
echo > Execute program
echo -----------------------
cmd /c IF EXIST $(NAME_PART).exe $(NAME_PART).exe

If you put this into a main.bat file or something it should give you a raylib runtime.

c0d3r
  • 109
  • 6
  • Thank you for taking the time to answer me, though I'm using Linux with regular old vim. –  Jan 10 '22 at 01:35
  • @μετα ohh, the compiler flags should be the same if you're using Gcc for your compilier. I reedit my answer to include those flags. – c0d3r Jan 12 '22 at 02:01
  • Thank you so much for answering, but unfortunately I don't understand how to use that knowledge under Linux. I also am underknowledged at how the linking process works at this very moment to be honest. I give you all my appreciation for helping me : ) –  Jan 12 '22 at 05:13
  • @μετα I am going, to be honest with you, It took me almost a year to understand this linking stuff in windows, it was like trying grasp air. My advice is to watch a video specifically on raylib and MinGW, like this: https://www.youtube.com/watch?v=Ew8h75KMHGY. Also for future reference, I am not this type of person, but a lot of people will delete these questions or give negative feedback. Don't let that get to you. I'm sorry I couldn't help you and happy coding. – c0d3r Jan 13 '22 at 03:22
  • 1
    You make me blush : ). -- Your inspiration is much valued -- My brain is broken that I'm have a terrible terrible time on how to tell how to make a good coding format. I have tried a lot, had many many downvotes and many many closures on Stack Exchange network. My heart was really wounded to be honest, especially several times, but I have a unique gift of simultaneously being able to recover quickly && transform kind advice like yours && others into a massive amount of all-any-way-I-can-find-helpful-fuel. So on that note thank you. on another note I've joined the raylib Discord and... –  Jan 13 '22 at 06:57
  • 1
    ... have helped me out so much. It is indeed a linking issue. I've turned to my trusty dusty Head First C book book to learn more about C. I'm starting from the beginning but I think it'll take me about a week to get through it && it has a chapter or whatever devoted to cmake -- which is what the helpful folks on the Discord channel have told me. //double-for-air. And up above I call my emotional selectivity philosophy the Dao of Meta, or Meta Dao to be short : ). Now in the event that I don't see you again, Good Day, Good Evening, and GoodNight :). –  Jan 13 '22 at 07:02
  • 1
    Post comment :: I will return to answer this question after I have my answered -- provide my answer for others. Now until then if anyone tries to crop my words or delete this comment under the Unreasonable clause of 'Stack Overflow' for any selfish reason, I will have my Llamacorn spit @ you -- normal llamas can spit up to about 10 feet away -- Llamacorns on the other hand spit Even further and they can pull this spit from their stomach on choice like Normal Llamas!... So - Until then -Good-Day Sir! –  Jan 13 '22 at 07:09
  • @μετα Here this should help, verbatim: https://stackoverflow.com/questions/68771383/a-problem-with-the-raylib-installation-on-linux – c0d3r Jan 14 '22 at 02:20
  • 1
    Sorry I was able to look at it a little bit, but yeah I think that it has what I needed. I would post my answer after looking at it but I'm about to be homeless in a few minutes. I hope everyone does well : ) –  Jan 14 '22 at 08:40