简体   繁体   中英

How do I sucessfully include SDL2 in Visual Studio 2017?

Please, if you think this can be done by yourself (and having tested it), please share steps instead of linking other guides. I have tried the following things in different ways:

Downloaded the SDL2 folder, it contains a lib and include folder.

  • Open my empty project containing the simple main function and all that (basic template)

  • Open Visual Studio's project properties

  • Add the include folder in "Additional Include Directories"

  • Add the lib folder in "Additional Library Directories"

  • Add the individual library files in "Additional Dependencies"

  • Include it

The download I have is from this page: https://www.libsdl.org/download-2.0.php

Under "Development Libraries" and under "Windows" I downloaded the VC.zip one.

Help? Please don't lock the thread, yes I have seen thousands of guides on how to do this. Why you think I ask here? Failure after failure, I'm getting nowhere.

I get a compile error which is something like this nonsense:

 Error LNK2019 unresolved external symbol _main referenced in function "int __cdecl invoke_main(void)" (?invoke_main@@YAHXZ) 

Here is my code:

#include <iostream>
#include <fstream>
#include <string>

#include <SDL.h>

using namespace std;

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

    cout << "Hello world!" << endl;

    return 0;

}

That happens because SDL uses #define main SDL_main and replaces the main function with it's own version. Linking with SDL2main.lib, which contains the implementation should get rid of the error. Alternatively you can add #undef main right before your main function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM