Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build fails on Windows when unicode is enabled due to incompatible entry point name with SDL2 #1472

Open
kalibera opened this issue Jan 20, 2025 · 3 comments
Labels
Milestone

Comments

@kalibera
Copy link

kalibera commented Jan 20, 2025

Building fluidsynth (version 2.4.2) for Windows fails when trying to link fluidsynth.exe, SDL_main is not found (SDL2 version 2.30.11), when unicode support (UNICODE) is enabled, which is the default. I am not sure whether it is a bug of fluidsynth or sdl2, but the technical cause is as follows.

SDL_main is supposed to be the entry point in the application, so in fluidsynth.exe, but it is not. The problem is that SDL2 expects that the application would define its entry point as "main" even when building with unicode enabled (and SDL2 renames it to "SDL_main"). See the SDL.h file:

/**
 *  \file SDL_main.h
 *
 *  The application's main() function must be called with C linkage,
 *  and should be declared like this:
 *  \code
 *  #ifdef __cplusplus
 *  extern "C"
 *  #endif
 *  int main(int argc, char *argv[])
 *  {
 *  }
 *  \endcode
 */

However, fluidsynth defines the entry point as "wmain", so it won't be renamed to SDL_main, and the symbol wouldn't be found. It is indeed not just the name of the entry point, but also the arguments - SDL2 expects that the entry point would accept narrow characters. One can build fluidsynth fine when "unicode" is disabled per cmake option "-Denable-unicode=OFF".

@kalibera kalibera added the bug label Jan 20, 2025
@derselbst derselbst added this to the 2.4 milestone Jan 20, 2025
@derselbst
Copy link
Member

Thanks for the report! Well, I am truly shocked. Hijacking a program's main function just because I included the SDL.h header is totally unacceptable! Also, the reason for this drastic measure isn't properly documented by SDL. Their reason to "run code before other code runs" is just the way most backdoors work. And IMO, it is a reason for completely removing SDL support, if we cannot prevent it from doing so. Esp. this is why any app is supposed to call SDL_Init() to handle the startup stuff.

I quickly looked through the SDL code. It seems that this part has undergone a few changes between SDL2 and SDL3. I will try to reproduce your finding, then I'll see if defining SDL_MAIN_HANDLED solves this problem appropriately.

@kalibera
Copy link
Author

Thanks for looking into this. I was surprised by the "main" replacement business as well. I assume the previous version of fluidsynth worked with SDL2 because it didn't use "UNICODE" (and I am using UCRT so I assume I don't need UNICODE, so I am happy disabling that in my builds).

@derselbst
Copy link
Member

SDL3 was just released yesterday, which no longer automatically includes SDL_main.h. Moving to SDL3 would be my preferable solution, but it requires a few code changes in fluid_sdl2.c. I'm not sure when I'll find time to do so, hence I'd welcome a PR. Until this is done, I will disable SDL2 support by default for the next fluidsynth release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy