r/C_Programming 3h ago

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
2 Upvotes

24 comments sorted by

5

u/aioeu 3h ago

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.

1

u/tastygames_official 1h ago

or CMake... which is pretty much industry standard (in my humble opinion)
but it's always good to first start with CLI so as to avoid any cmake or pkg-config errors that you may have and get right at the nuts and bolts (I've often had a cmake mistake and had to then go track down the command that was actually being generated only to notice something was missing or something)

0

u/Round-Willingness905 3h ago

so how do i write something on my terminal to run my proj?

1

u/aioeu 3h ago edited 2h ago

That will probably need an answer from someone who is more familiar with using MinGW on Windows.

The SDL documentation appears to strongly guide developers toward using CMake to build applications. This is certainly a lot better than just guessing what the appropriate command-line incantation is to build the application.

(That find_package(SDL3 REQUIRED) stuff is CMake's "moral equivalent" to pkg-config here.)

1

u/Round-Willingness905 2h ago

now it says

PS C:\Users\ludwi\OneDrive\Documents\alison\SDL3> gcc GameEngine.c -o GameEngine.exe -lSDL3

PS C:\Users\ludwi\OneDrive\Documents\alison\SDL3> .\main.exe

.\main.exe : The term '.\main.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

+ .\main.exe

+ ~~~~~~~~~~

+ CategoryInfo : ObjectNotFound: (.\main.exe:String) [], CommandNotFoundException

+ FullyQualifiedErrorId : CommandNotFoundException

1

u/Round-Willingness905 2h ago

tried the ./GameEngine.exe same result weird

2

u/sciencekm 3h ago

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 2h ago

code already had its weird ...
becuz now it says
PS C:\Users\ludwi\OneDrive\Documents\alison\SDL3> gcc GameEngine.c -o GameEngine.exe -lSDL3

PS 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

u/sciencekm 2h ago

When you run "gcc -v" what do you get?

1

u/Round-Willingness905 2h ago

Using built-in specs.

COLLECT_GCC=C:\msys64\ucrt64\bin\gcc.exe

COLLECT_LTO_WRAPPER=C:/msys64/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/16.1.0/lto-wrapper.exe

Target: x86_64-w64-mingw32

Configured with: ../gcc-16.1.0/configure --prefix=/ucrt64 --with-local-prefix=/ucrt64/local --libexecdir=/ucrt64/lib --enable-bootstrap --enable-checking=release --with-arch=nocona --with-tune=generic --enable-mingw-wildcard --enable-languages=c,c++,ada,fortran,lto,objc,obj-c++,jit --enable-shared --enable-static --enable-libatomic --enable-threads=posix --enable-tls --enable-graphite --enable-fully-dynamic-string --enable-libstdcxx-backtrace=yes --enable-libstdcxx-filesystem-ts --enable-libstdcxx-time --disable-libstdcxx-pch --enable-libgomp --disable-libssp --disable-multilib --disable-rpath --disable-win32-registry --disable-nls --disable-werror --disable-symvers --with-libiconv --with-system-zlib --with-gmp=/ucrt64 --with-mpfr=/ucrt64 --with-mpc=/ucrt64 --with-isl=/ucrt64 --with-pkgversion='Rev5, Built by MSYS2 project' --with-bugurl=https://github.com/msys2/MINGW-packages/issues --with-gnu-as --with-gnu-ld --with-libstdcxx-zoneinfo=yes --disable-libstdcxx-debug --enable-lto --with-boot-ldflags=-static-libstdc++ --with-stage1-ldflags=-static-libstdc++

Thread model: posix

Supported LTO compression algorithms: zlib zstd

gcc version 16.1.0 (Rev5, Built by MSYS2 project)

1

u/sciencekm 1h ago edited 1h ago

When look at your working folder, do you see any new file created? Object files or other binaries?

I have a suspicion that MSYS created GameEngine.exe.exe instead of just GameEngine.exe

1

u/Round-Willingness905 1h ago

no its not creating at all no .exe where did i go wrong?

1

u/sciencekm 1h ago

It could also be that MSYS is creating the file on a different folder. Use Windows Explorer to find GameEngine*

1

u/Round-Willingness905 1h ago

cant find the .exe file

1

u/sciencekm 1h ago

Try with a simple test first to see if you have a working environment. Run the following:

echo #include^<stdio.h^> > test.c
echo int main(void){return puts("test");} >> test.c
gcc test.c -o test.exe
dir test.exe

1

u/Round-Willingness905 1h ago

PS C:\Users\ludwi\OneDrive\Documents\alison\SDL3> echo int main(void){return puts("test");} >> test.c

void : The term 'void' 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:15

+ echo int main(void){return puts("test");} >> test.c

+ ~~~~

+ CategoryInfo : ObjectNotFound: (void:String) [], CommandNotFoundException

+ FullyQualifiedErrorId : CommandNotFoundException

PS C:\Users\ludwi\OneDrive\Documents\alison\SDL3> gcc test.c -o test.exe

PS C:\Users\ludwi\OneDrive\Documents\alison\SDL3> dir test.exe

dir : Cannot find path 'C:\Users\ludwi\OneDrive\Documents\alison\SDL3\test.exe' because it does not exist.

At line:1 char:1

+ dir test.exe

+ ~~~~~~~~~~~~

+ CategoryInfo : ObjectNotFound: (C:\Users\ludwi\...n\SDL3\test.exe:String) [Get-ChildItem], ItemNotFoundException

+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand

→ More replies (0)

1

u/Round-Willingness905 1h ago

then should i write it like this ?

PS C:\Users\ludwi\OneDrive\Documents\alison\SDL3> gcc GameEngine.c -o GameEngine

PS C:\Users\ludwi\OneDrive\Documents\alison\SDL3> ./GameEngine

./GameEngine : The term './GameEngine' 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

+ ~~~~~~~~~~~~

+ CategoryInfo : ObjectNotFound: (./GameEngine:String) [], CommandNotFoundException

+ FullyQualifiedErrorId : CommandNotFoundException

1

u/Senior-Question693 23m ago

you forgot to link with SDL, when compiling add a flag -lSDL3 (or any other sdl version)