1

Before I start, I know there are a lot of other questions on stack that are the same as mine. Trust me, I've checked them all, and I wouldn't be asking this question if they had helped me in any way shape or form. Also I would very much like an easy to understand answer, because while looking at the other questions, it took me 10 minutes of looking at them just to figure out what they meant. That being said, let's get to my problem.

I am trying to get SDL to work with Visual Studio Code (Not Visual Studio. My computer doesn't have enough space for Visual Studio or I'd be using it.) I am in the tasks.json file trying to link the SDL2.lib library to the file I'm working with, main.cpp (I'm using c++). I have moved all the files in the SDL include and lib folders to be loose in my mingw bin folder. This is my tasks.json file:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "echo",
            "type": "shell",
            "command": "g++",
            "args": [
               "-g",
               "-o",
               "-c",
               "C:/MinGW/bin/main.cpp",
               "C:/MinGW/bin/SDL2.lib",
               "-lmingw32"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": [
                "$gcc"
            ]
        },
    ]
}

And here is my main.cpp file:

#include "windows.h"
#include "SDL.h"
#include <iostream>

int main(int argc, char** argv) {

    SDL_Init(SDL_INIT_EVERYTHING);

    return 0;
}

I get the following error:

c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../libmingw32.a(main.o):(.text.startup+0xa0): undefined reference to `WinMain@16'
collect2.exe: error: ld returned 1 exit status
The terminal process terminated with exit code: 1

From what I can tell, this error is fairly common, but I have been keeping track, and over the past two weeks, I have tried 37 different ways to solve this problem (including the solutions to the other posts about this). I don't know what the problem is, but maybe someone here can figure it out. I have posted this in four other forums with no responses and I am so lost. It's really hard to be enthusiastic right now, but please respond and thank you in advance!

Jiffis28
  • 65
  • 1
  • 7
  • have you tried int WinMain(..) ? this project is a Windows Application not a console ,right? – 138 Aug 29 '18 at 22:57

1 Answers1

1

Try adding this line before your SDL include:

#define SDL_MAIN_HANDLED

Look here for more details:

undefined reference to `WinMain@16'

paulsm4
  • 114,292
  • 17
  • 138
  • 190
  • Cool - thank you for the update. Please feel free to "accept" this answer (so the question won't remain "open"). – paulsm4 Sep 03 '18 at 17:36