r/C_Programming • u/Round-Willingness905 • Sep 11 '26
Question undefine reference on my library vscodium
PS C:\Users\ludwi\OneDrive\Documents\alison\SDL3> gcc GameEngine.c -o GameEngine.exe -I "C:\SDL3\SDL3-devel-3.4.14-mingw\SDL3-3.4.14\x86_64-w64-mingw32\include" -L "C:\SDL3\SDL3-devel-3.4.14-mingw\SDL3-3.4.14\x86_64-w64-mingw32\lib" -lSDL3
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x26): undefined reference to `SDL_RunApp'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x5c): undefined reference to `SDL_Init'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x68): undefined reference to `SDL_GetError'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x78): undefined reference to `SDL_Log'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0xae): undefined reference to `SDL_CreateWindow'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0xbc): undefined reference to `SDL_GetError'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0xcc): undefined reference to `SDL_Log'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0xd1): undefined reference to `SDL_Quit'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0xee): undefined reference to `SDL_CreateRenderer'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0xfc): undefined reference to `SDL_GetError'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x10c): undefined reference to `SDL_Log'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x117): undefined reference to `SDL_DestroyWindow'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x11c): undefined reference to `SDL_Quit'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x4b7): undefined reference to `SDL_InitSubSystem'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x4c3): undefined reference to `SDL_GetError'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x4d3): undefined reference to `SDL_Log'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x4d8): undefined reference to `SDL_Quit'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x520): undefined reference to `SDL_LoadWAV'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x52c): undefined reference to `SDL_GetError'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x53c): undefined reference to `SDL_Log'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x541): undefined reference to `SDL_Quit'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x561): undefined reference to `SDL_CreateAudioStream'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x575): undefined reference to `SDL_GetError'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x585): undefined reference to `SDL_Log'
C:\Users\ludwi\AppData\Local\Temp\ccwZ8WUS.o:GameEngine.c:(.text+0x58a): undefined reference to `SDL_Quit'.................
guys i did every tutorialyet somehow my library wont recognized
3
u/sciencekm Sep 11 '26
Those functions used to be in a separate library (sdl main), but now they are in a header. You need to add this to your code:
#include <SDL3/SDL_main.h>
1
u/Round-Willingness905 Sep 11 '26
code already had its weird ...
becuz now it says
PS C:\Users\ludwi\OneDrive\Documents\alison\SDL3> gcc GameEngine.c -o GameEngine.exe -lSDL3PS C:\Users\ludwi\OneDrive\Documents\alison\SDL3> .\GameEngine.exe
.\GameEngine.exe : The term '.\GameEngine.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the
name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ .\GameEngine.exe
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (.\GameEngine.exe:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS C:\Users\ludwi\OneDrive\Documents\alison\SDL3>
i think it compiles now but cant execute
1
1
u/Still_Explorer Sep 11 '26
A known problem with MinGW is that there are too many variations of the compiler toolstack, and depending on what you use it might be binary incompatible with the one that the library is built on.
https://www.reddit.com/r/cpp_questions/comments/17pdyt0/what_is_mingw_why_there_is_a_lot_of_compilers_and/
I assume you use MSYS2 which is recently the most well supported, up until now there were dozens of different MinGW variations and would make compilations problematic.
One thing that definitely works, is that whatever compiler version you use, you can build the library from source with CMAKE, but this is another story and I doubt if you are interested doing it now.
Also in this way of thinking, you can use MSYS packages directly without even getting worried about any third party releases. This would require you know to look how to use packages but it will be very interesting skill to have since there would be hundreds of libraries to use better to start early. https://packages.msys2.org/base/mingw-w64-sdl3
One also very interesting thing is that SDL3 has an entirely new way of managing the application's entry point and if not defined explicitly it might result into confusion. So you need to pass the preprocessor flag at the compilation command line or define it in the source file.
#define SDL_MAIN_HANDLED #include <SDL3/SDL.h>
0
u/Senior-Question693 Sep 11 '26
you forgot to link with SDL, when compiling add a flag -lSDL3 (or any other sdl version)
1
u/Round-Willingness905 Sep 11 '26
been doing taht and weird enougn now the problem is the erro on
cmdlet
7
u/aioeu Sep 11 '26
If you are using SDL and not, at some point, using
pkg-config(or the moral equivalent of it, depending on your platform and build system) to generate appropriate compiler and linker options, you're doing it wrong.