0

I'm new to C++ and libraries. Recently I've tried using Raylib. But I can't seem to fix the error below (I'm on a windows device):

collect2.exe: error: ld returned 1 exit status
PS C:\Users\idkbo\OneDrive\Masaüstü\NewScripts\clang\cpp\game> g++ gametest.cpp -I C:\raylib\raylib\src
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\idkbo\AppData\Local\Temp\ccMXZKeE.o:gametest.cpp:(.text+0x30): undefined reference to `InitWindow'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\idkbo\AppData\Local\Temp\ccMXZKeE.o:gametest.cpp:(.text+0x3a): undefined reference to `SetTargetFPS'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\idkbo\AppData\Local\Temp\ccMXZKeE.o:gametest.cpp:(.text+0x41): undefined reference to `BeginDrawing'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\idkbo\AppData\Local\Temp\ccMXZKeE.o:gametest.cpp:(.text+0x69): undefined reference to `ClearBackground'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\idkbo\AppData\Local\Temp\ccMXZKeE.o:gametest.cpp:(.text+0xad): undefined reference to `DrawText'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\idkbo\AppData\Local\Temp\ccMXZKeE.o:gametest.cpp:(.text+0xb2): undefined reference to `EndDrawing'
C:/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\idkbo\AppData\Local\Temp\ccMXZKeE.o:gametest.cpp:(.text+0xb7): undefined reference to `WindowShouldClose'
collect2.exe: error: ld returned 1 exit status

How can I solve this?

I searched for some solutions but all of them were in C. I copied the code from Raylib Examples. It's really annoying to have bugs like this since I'm new and I don't understand a single character of what these mean, I'd really appreciate any help!

drescherjm
  • 10,365
  • 5
  • 44
  • 64
fsd
  • 1
  • 1
  • `g++ gametest.cpp -I C:\raylib\raylib\src` Looks like your problem is that you did not link to any library. – drescherjm Nov 06 '22 at 14:18
  • What do you mean? How can I link to a library? – fsd Nov 06 '22 at 14:20
  • `-l` is link in gcc/ g++ `-L` adds an additional folder for the linker to search . Here are a few guides on how to link for your compiler: [https://www.linuxtopia.org/online_books/an_introduction_to_gcc/gccintro_17.html](https://www.linuxtopia.org/online_books/an_introduction_to_gcc/gccintro_17.html) and [https://www.rapidtables.com/code/linux/gcc/gcc-l.html](https://www.rapidtables.com/code/linux/gcc/gcc-l.html) – drescherjm Nov 06 '22 at 14:20
  • I just added a few tutorials. You would need to read the documentation on raylib to determine what libraries are needed. – drescherjm Nov 06 '22 at 14:24
  • With all of that said you may just want to use the getting started instructions from raylib instead of manual building: [https://github.com/raysan5/raylib/wiki/Working-on-Windows](https://github.com/raysan5/raylib/wiki/Working-on-Windows) however it's a good idea to understand how to use your compiler from the command line. – drescherjm Nov 06 '22 at 14:26
  • Were you able to solve it? I am running into a similar error with VSC++ (from command line): main.c main.obj : error LNK2019: unresolved external symbol InitWindow referenced in function main main.obj : error LNK2019: unresolved external symbol WindowShouldClose referenced in function main .... – programmer Apr 03 '23 at 18:05

0 Answers0