1

I have been trying to get SDL2 to work in my environment but have had no luck. I am using Windows 10 Home with MinGW, working in Eclipse IDE for C/C++ Developers.

I downloaded SDL2.26.4 from this GitHub repository.

After downloading and extracting the files, I copied the contents of the SDL2 include and lib files to my MinGW folder in C:\MinGW.

In my IDE, I added the include and library paths.

enter image description here

enter image description here

I also included some recommended linker flags suggested from other solutions, but they have had no impact.

enter image description here

When I run the following code:

#include <iostream>
#define SDL_MAIN_HANDLED
#include <SDL.h>
using namespace std;

int main() {
    cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
    return 0;
}

...I am met with errors:

C:\Users\User\eclipse-workspace\SDL2 test\Debug/../src/SDL2 test.cpp:12: multiple definition of `main'
C:\MinGW\lib/libmingw32.a(main.o):(.text.startup+0x0): first defined here
C:\MinGW\lib/libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status

I've tried recreating my project, putting my include and library folders in different file locations, different variations of inhibiting SDL from redefining my 'main' function, but nothing has worked.

genpfault
  • 51,148
  • 11
  • 85
  • 139
Jujimufoo
  • 27
  • 3
  • Refer to [How do I use SDL2 in my programs correctly?](https://stackoverflow.com/a/64396980/2752075). – HolyBlackCat Apr 01 '23 at 07:37
  • I've followed every piece of advice offered in the link you provided and still am met with "undefined reference to `WinMain@16'". All of my linker flags are set, my include files and libraries are identified, I have experimented with using 32 and 64 bit versions of the SDL2 package, but have not made any progress. – Jujimufoo Apr 01 '23 at 14:30
  • After reviewing this https://stackoverflow.com/questions/5259714/undefined-reference-to-winmain16 answer provided by genpfault, I experimented by changing my main() function to WinMain(), at which point the program was able to be compiled. – Jujimufoo Apr 01 '23 at 14:37
  • Renaming it shouldn't be necessary. Did you remove `SDL_MAIN_HANDLED` as the post suggests in the preamble? – HolyBlackCat Apr 01 '23 at 14:52
  • Yes, I removed SDL_MAIN_HANDLED from the beginning of my script. Also, I spoke too soon earlier; while the code was able to be compiled and execute "Hello World", as soon as I started calling SDL-specific functions I was met with more "undefined reference to 'SDL_main'" errors. I have been troubleshooting this development since. – Jujimufoo Apr 01 '23 at 17:02
  • I'm fairly sure the linked guide covers everything that could go wrong (except for some really weird scenarios). Double-check that you're following everything. E.g. perhaps you experimented with x32 vs x64 libs, but the compiler was using libs located elsewhere. – HolyBlackCat Apr 01 '23 at 17:09
  • I did eventually get SDL to launch in a new IDE. I changed from Eclipse to Visual Studio Code. I was using Eclipse to follow along with a guide as closely as possible, but this will have to do. Thank you for all the help! – Jujimufoo Apr 02 '23 at 01:16

0 Answers0