I’m trying to set up SDL2 with MinGW in C++ in VS Code, and I’ve been following along with this tutorial. I have tried importing include
and lib
from the directories x86_64-w64-mingw32
and i686-w64-mingw32
but after using make all
it returns:
PS C:UserswilliOneDriveDesktopC++projectsfirst-game> make all g++ -Isrc/include -Lsrc/lib -lmingw32 -lSDL2main -lSDL2 -o main
main.cpp
C:/mingw/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
C:UserswilliAppDataLocalTempccVjnkZ5.o:main.cpp:(.text+0x15):
undefined reference toSDL_Init' C:/mingw/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:UserswilliAppDataLocalTempccVjnkZ5.o:main.cpp:(.text+0x21): undefined reference to
SDL_GetError’
C:/mingw/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
C:UserswilliAppDataLocalTempccVjnkZ5.o:main.cpp:(.text+0x6d):
undefined reference toSDL_CreateWindow' C:/mingw/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:UserswilliAppDataLocalTempccVjnkZ5.o:main.cpp:(.text+0x7d): undefined reference to
SDL_GetError’
C:/mingw/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
C:UserswilliAppDataLocalTempccVjnkZ5.o:main.cpp:(.text+0xb0):
undefined reference toSDL_CreateRenderer' C:/mingw/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:UserswilliAppDataLocalTempccVjnkZ5.o:main.cpp:(.text+0xc0): undefined reference to
SDL_GetError’
C:/mingw/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
C:UserswilliAppDataLocalTempccVjnkZ5.o:main.cpp:(.text+0xfc):
undefined reference toSDL_PollEvent' C:/mingw/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:UserswilliAppDataLocalTempccVjnkZ5.o:main.cpp:(.text+0x12a): undefined reference to
SDL_SetRenderDrawColor’
C:/mingw/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
C:UserswilliAppDataLocalTempccVjnkZ5.o:main.cpp:(.text+0x136):
undefined reference toSDL_RenderClear' C:/mingw/ucrt64/bin/../lib/gcc/x86_64-w64-mingw32/13.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:UserswilliAppDataLocalTempccVjnkZ5.o:main.cpp:(.text+0x142): undefined reference to
SDL_RenderPresent’ collect2.exe: error: ld
returned 1 exit status make: *** [Makefile:2: all] Error 1
If anyone could help me resolve this issue, that would be greatly appreciated, thanks!
I’ve tried asking for help here on the Together C & C++ discord server, where someone pointed out that “The problem is it’s getting linked, just not everything is getting linked, so it’s missing some references”.
Monnt is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.