0

I get this error:

C:\Users\User\AppData\Local\Temp\cce4CTZf.o:window.cpp:(.text+0xe): undefined reference to `SDL_Init'
C:\Users\User\AppData\Local\Temp\cce4CTZf.o:window.cpp:(.text+0x42): undefined reference to `SDL_CreateWindow'
C:\Users\User\AppData\Local\Temp\cce4CTZf.o:window.cpp:(.text+0x50): undefined reference to `SDL_GetWindowSurface'
C:\Users\User\AppData\Local\Temp\cce4CTZf.o:window.cpp:(.text+0x5f): undefined reference to `SDL_Delay'
C:\Users\User\AppData\Local\Temp\cce4CTZf.o:window.cpp:(.text+0x6a): undefined reference to `SDL_DestroyWindow'
C:\Users\User\AppData\Local\Temp\cce4CTZf.o:window.cpp:(.text+0x6f): undefined reference to `SDL_Quit'
e:/work/mingw/bin/../lib/gcc/mingw32/4.4.0/../../../libmingw32.a(main.o):main.c:(.text+0xd2): undefined reference to `WinMain@16'
collect2: ld returned 1 exit status

when trying to compile this code:

#include <SDL2/SDL.h>

int main(int argc, char ** arg )
{
    SDL_Init(SDL_INIT_EVERYTHING);
    SDL_Window * win = SDL_CreateWindow("Game", 30, 30, 600, 500, SDL_WINDOW_SHOWN);
    SDL_Surface * screen = SDL_GetWindowSurface(win);
    SDL_Delay(2000);
    SDL_DestroyWindow(win);
    SDL_Quit();
}

I tried making a new "include" path where the headers are stored, but it didn't work. I also tried just including the headers in the project folder itself, also didn't work.

Edit: I managed to compile the app.

Shrug
  • 3
  • 4
  • What compiler/linker flags did you use? In any case, the linked thread should have everything you need. Also, GCC 4.4 has to be the oldest GCC I've seen in a while. Get yourself GCC 11 from [MSYS2](https://stackoverflow.com/q/30069830/2752075). – HolyBlackCat Apr 04 '22 at 15:02
  • This has nothing to do with include paths or headers at all. Its that you did not link to the required libraries. Why are you using a such an old version of gcc / mingw? This may be part of your problem. – drescherjm Apr 04 '22 at 15:05
  • @drescherjm You say that the libraries are not linked, how can I link them? – Shrug Apr 04 '22 at 15:47
  • It depends on how you are building. The simplest way is to back up and replace your current mingw with the version in MSYS2 and install SDL2 via pacman that is the package manager in msys2. See the first link for instructions on how to properly install sdl2 with a modern mingw. After you do that you will have to explain how you are compiling in the first place. There are several IDEs you can use and CMake, Makefiles or just building on the command line. Depending on your choice you may have to spend some time learning your compiler's command line switches – drescherjm Apr 04 '22 at 16:09
  • @drescherjm I don't know how to use pacman to install SDL2 – Shrug Apr 04 '22 at 16:48
  • It will be very similar to this: [https://stackoverflow.com/a/30071634/487892](https://stackoverflow.com/a/30071634/487892) When you google a package the msys2 documentation gives you the exact command to run: [https://packages.msys2.org/package/mingw-w64-x86_64-SDL2](https://packages.msys2.org/package/mingw-w64-x86_64-SDL2) In the mingw64 terminal that you installed when you installed msys2 you type `pacman -S mingw-w64-x86_64-SDL2` – drescherjm Apr 04 '22 at 16:49

0 Answers0