File: fix-gcc15-extern-c-main.patch

package info (click to toggle)
colobot 0.2.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 415,532 kB
  • sloc: cpp: 129,246; ansic: 8,872; python: 2,158; sh: 672; awk: 91; xml: 35; makefile: 31
file content (51 lines) | stat: -rw-r--r-- 1,684 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
From 1561854b03500d39955c66971c9c98de1937d7e6 Mon Sep 17 00:00:00 2001
From: suve <veg@svgames.pl>
Date: Thu, 16 Jan 2025 16:33:33 +0100
Subject: [PATCH] Check if SDL_main is in use

The main() function of colobot-app is declared as extern "C" to prevent
name mangling. This is required because on some platforms, SDL2 declares
its own main() function and defines a macro that renames the user's main
to SDL_main; in which case, name mangling may cause linking failures.

However, when building for platforms where this is not the case,
gcc15 complains that specifying linkage for main is not allowed.
> error: cannot declare ‘::main’ with a linkage
>        specification [-Wpedantic]

This commit wraps the extern block in #ifdefs that check
if the main -> SDL_main macro is in use.

Bug-Debian: https://bugs.debian.org/1096454
Forwarded: https://github.com/colobot/colobot/issues/1873
---
 colobot-app/src/main.cpp | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/colobot-app/src/main.cpp b/colobot-app/src/main.cpp
index df4864007..4614c2138 100644
--- a/src/app/main.cpp
+++ b/src/app/main.cpp
@@ -101,10 +101,14 @@ The current layout is the following:
  - src/script - link with the CBot library
 */
 
-//! Entry point to the program
+// On *some* platforms, SDL declares a macro which renames main to SDL_main.
+// If that's the case, use "extern C" to prevent name mangling.
+#ifdef main
 extern "C"
 {
+#endif
 
+//! Entry point to the program
 int main(int argc, char *argv[])
 {
     CLogger logger; // single instance of logger
@@ -203,4 +207,6 @@ int main(int argc, char *argv[])
     return code;
 }
 
+#ifdef main
 } // extern "C"
+#endif