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

[MinGW] Missing option for static-linking libstdc++ (self-contained .exe) #761

Open
olekolek1000 opened this issue Jan 7, 2024 · 0 comments

Comments

@olekolek1000
Copy link

olekolek1000 commented Jan 7, 2024

Describe the bug
Currently, imgui links with shared library libstdc++ and libgcc, causing the executable to not be portable (useful in making installers or portable apps). There should be an option to static-link stdc++ with the libcimgui.a.

To Reproduce

  1. Compile executable with imgui-rs and statically-compiled SDL2
  2. Try to run it outside development environment
  3. "Cannot find libstdc++-6.dll"

Expected behavior
Application runs without any external dependencies

Please describe your environment

  • imgui-rs main
  • Microsoft Windows (MSYS2 MinGW UCRT64)

Other information
Working fix (needs customization, wip)

diff --git a/imgui-sdl2-support/Cargo.toml b/imgui-sdl2-support/Cargo.toml
index 5935df8..08a4301 100644
--- a/imgui-sdl2-support/Cargo.toml
+++ b/imgui-sdl2-support/Cargo.toml
@@ -12,7 +12,7 @@ categories = ["gui"]

 [dependencies]
 imgui = { version = "0.11.0", path = "../imgui" }
-sdl2 = "0.36.0"
+sdl2 = { version = "0.36.0", features = ["bundled", "static-link"] }

 [dev-dependencies]
 glow = "0.12.0"
diff --git a/imgui-sys/build.rs b/imgui-sys/build.rs
index 0951589..ffb9d7f 100644
--- a/imgui-sys/build.rs
+++ b/imgui-sys/build.rs
@@ -58,10 +58,10 @@ fn main() -> std::io::Result<()> {
     if !wasm_enabled {
         // C++ compiler
         let mut build = cc::Build::new();
-        build.cpp(true);
+        build.cpp(false);

         // imgui uses C++11 stuff from v1.87 onwards
-        build.flag_if_supported("-std=c++11");
+        build.flag("-std=gnu++11");

         // Set defines for compiler
         for (key, value) in DEFINES.iter() {
@@ -104,11 +104,11 @@ fn main() -> std::io::Result<()> {
         // Avoid the if-supported flag functions for easy cases, as they're
         // kinda costly.
         if compiler.is_like_gnu() || compiler.is_like_clang() {
-            build.flag("-fno-exceptions").flag("-fno-rtti");
+            build.flag("-fno-exceptions").flag("-fno-rtti").flag("-fno-threadsafe-statics");
         }

         // Build imgui lib, suppressing warnings.
-        build.warnings(false).file(imgui_cpp).compile("libcimgui.a");
+        build.warnings(false).file(imgui_cpp).static_flag(true).shared_flag(false).compile("libcimgui.a");
     }
     Ok(())
 }

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

No branches or pull requests

1 participant