0

so i tried to build my raylib code but it fails and givesme bunch of errors. can anyone help me to fix this issue?

#include "C:\raylib\raylib\src\raylib.h"

int main(void) {
  const int width = 1024;
  const int height = 512;

  InitWindow(width, height, "raycaster go brr");

  SetTargetFPS(60);

  while (!WindowShouldClose()) {
    BeginDrawing();

      ClearBackground(RAYWHITE);

    EndDrawing();
  }

  CloseWindow();

  return 0;
}
cc1plus.exe: warning: command line option '-std=c99' is valid for C/ObjC but not for C++
C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lraylib
collect2.exe: error: ld returned 1 exit status

raylib.h is located at C:\raylib\raylib\src

I use this piece of text to build my programm

g++ main.cpp -o main -O1 -Wall -std=c99 -Wno-missing-braces -L ./lib/ -lraylib -lopengl32 -lgdi32 -lwinmm

Update:

i linked libraylib.a to my c++ project and tried to build it, but i still got more errors. libraylib.a is located in C:\raylib\raylib\src

g++ main.cpp -o main -O1 -Wall -Wno-missing-braces -LC:/raylib/raylib/src  -lraylib -lopengl32 -lgdi32 -lwinmm

Errors:

C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/raylib/raylib/src/libraylib.a when searching for -lraylib
C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/raylib/raylib/src\libraylib.a when searching for -lraylib
C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible C:/raylib/raylib/src/libraylib.a when searching for -lraylib
C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lraylib
collect2.exe: error: ld returned 1 exit status
  • And where is `libraylib.a` located? – Some programmer dude Nov 22 '22 at 07:49
  • Also please pay attention to the warning about `-std=c99`. Why did you add that option? – Some programmer dude Nov 22 '22 at 07:49
  • @Someprogrammerdude in C:\raylib\raylib\src – NikoMolecule Nov 22 '22 at 07:51
  • Then add `-LC:/raylib/raylib/src` when building, to tell the linker to look in that directory for libraries. – Some programmer dude Nov 22 '22 at 07:52
  • I also recommend you install MSYS2 instead plain stand-alone MinGW, which gives you an almost Linux-like environment where you can install packages, like Raylib, and it will be considered "system" libraries by the MSYS2 MinGW compiler and linker. – Some programmer dude Nov 22 '22 at 07:54
  • @Someprogrammerdude i got more errors after i added ```-LC:/raylib/raylib/src``` – NikoMolecule Nov 22 '22 at 07:57
  • Please don't make us play [a 20 questions game](https://en.wikipedia.org/wiki/Twenty_questions) with you. [Edit] your question to give us all details needed to help you. – Some programmer dude Nov 22 '22 at 07:59
  • How did you build raylib? With the same version of MinGW as you use to build your own application? – Some programmer dude Nov 22 '22 at 08:14
  • @Someprogrammerdude i installed it with mingw from official website, how to check if they are same version? – NikoMolecule Nov 22 '22 at 08:17
  • Don't use `#include "C:\raylib\raylib\src\raylib.h"` but use `#include ` combined with compiler flag `-IC:\raylib\raylib\src`. For the linker you will need linker flags `-LC:\raylib\raylib\src` and `-lraylib` (assuming the library file is `C:\raylib\raylib\src\libraylib.a`). – Brecht Sanders Nov 22 '22 at 10:49
  • The last errors you get indicate `libraylib.a` is not compatible with your compiler/platform. For example you may be mixing 32-bit and 64-bit. If you want to be sure there are no mismatches install CMake and Ninja and build raylib from source with the same compiler/linker. – Brecht Sanders Nov 22 '22 at 13:15

0 Answers0