Repository: Rust-SDL2/rust-sdl2 (language: rust)

Issue:
Linking error on Windows with static SDL when Rust is also linked to other C++ application
Error message:

```
obliteration.lib(SDL_windows_main.obj) : error LNK2005: main already defined in main.obj [D:\a\obliteration\obliteration\build\src\obliteration.vcxproj]
```

My project consist 2 parts:

1. C++ using Qt
2. Rust library output as `staticlib`

When the first one linking the second the above error happened. You can see a full build log here: https://github.com/ultimaweapon/obliteration/actions/runs/3076288688/jobs/4970339763


Discussion / hints:
This error/issue seems to be outside the scope of this crate and needs expertise on the C++/Rust interop side, so I'm closing this. If you think there is a bug within this crate itself related to your issue, feel free to reopen while explaining clearly what is going wrong compared to the same C / C++ application.
I believed it is a bug of this crate. From the error it mean `main` function have been defined by SDL, which get compiled by this crate when enable `static-link` feature.

From a remark in the [SDL documentation](https://wiki.libsdl.org/SDL_SetMainReady) it seem like it is required to define `SDL_MAIN_HANDLED` when building SDL so it not including its `main` which cause a conflict with `main` of the application.

Fix patch:
diff --git a/sdl2-sys/build.rs b/sdl2-sys/build.rs
index f58384d728..fc4bd92653 100644
--- a/sdl2-sys/build.rs
+++ b/sdl2-sys/build.rs
@@ -135,6 +135,9 @@ fn compile_sdl2(sdl2_build_path: &Path, target_os: &str) -> PathBuf {
     if cfg!(feature = "static-link") {
         cfg.define("SDL_SHARED", "OFF");
         cfg.define("SDL_STATIC", "ON");
+        // Prevent SDL to provide it own "main" which cause a conflict when this crate linked
+        // to C/C++ program.
+        cfg.define("SDL_MAIN_HANDLED", "ON");
     } else {
         cfg.define("SDL_SHARED", "ON");
         cfg.define("SDL_STATIC", "OFF");


Test patch: