1

I keep getting these errors:

error LNK2005: _main already defined in main.obj
error LNK2019: unresolved external symbol _SDL_main referenced in function _main_utf8
error LNK1120: 1 unresolved externals

when building this

#include <stdio.h>
#include <SDL.h>
int main(int argc, const char* argv[]){
 printf("Hi\n");
 return 0;
}

I've set up the directories and the linker in Visual Studio 2013, but I can't figure out what went wrong. I'm using the 32 bit SDL runtime library. I'm also fairly new to C++.

Flexo - Save the data dump
89.1k22 gold badges205 silver badges286 bronze badges
asked May 28, 2016 at 19:25
1

1 Answer 1

2

Before your main function, define

#define SDL_MAIN_HANDLED

This stops SDL's "service" of parsing the command line for you(only on windows). Though this is a fix, this isn't good for cross platform programs. The other fix is to change main so that it looks like this:

int main(int argc, char* argv[])

You must do this because of the main macro defined in SDL_Main.h that forces you to have exactly that otherwise it will give you the error you have.

answered Oct 18, 2016 at 22:52
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.