rust-sfml icon indicating copy to clipboard operation
rust-sfml copied to clipboard

Feature: Allow statically linking libstdc++ in the build.rs

Open donicrosby opened this issue 2 years ago • 4 comments

When building a binary for Windows or other hosts that have different libstdc++ implementations it would be nice to be able to statically link libstdc++ for the library so that final programs don't need to ship the shared libs or the dlls for windows.

donicrosby avatar Jan 07 '23 19:01 donicrosby

I'm using the link-cplusplus crate for linking the C++ standard library, but it doesn't seem to have a static option.

crumblingstatue avatar Jan 09 '23 13:01 crumblingstatue

I have been playing around with how to do this, I'll probably make a PR hopefully some time this week. It's really making sure you have the correct libstdc++.a for the compiler

donicrosby avatar Jan 09 '23 14:01 donicrosby

Just make sure that you don't change how dynamic linking works. So this libstdc++ specific code should only happen when static linking is requested.

crumblingstatue avatar Jan 10 '23 00:01 crumblingstatue

Necro post but it seems that you cannot use CSFML statically any way (because SFML is built in C++). With the MSVC build of SFML I just need OpenAL and the SFML dlls (nothing related to stdc++).

I've though a bit about this whole bindgen stuff but it seems that some stuff SFML is doing is not supported and will never be (because that's way to complex to handle, inline, template etc...)

Regarding the fact your need to bundle the dlls on Windows is not really a big issue, almost all programs do it, the cool thing with Windows is that you don't have to specify a LD_LIBRARY_PATH, by default it looks into executable's current folder and if your executable is specifying dependent manifest you're able to move the dlls into a sub folder.

Regarding the environment setup. On my project I added a deps folder which holds SFML-2.6 binaries in a folder (extraction of the zip in a folder of the same name) and my workspace's settings.json contains:

  "rust-analyzer.cargo.extraEnv": {
    "SFML_INCLUDE_DIR": "${workspaceFolder}\\deps\\SFML-2.6.0\\include",
    "SFML_LIBS_DIR": "${workspaceFolder}\\deps\\SFML-2.6.0\\lib"
  },
  "rust-analyzer.runnables.extraEnv": {
    "SFML_INCLUDE_DIR": "${workspaceFolder}\\deps\\SFML-2.6.0\\include",
    "SFML_LIBS_DIR": "${workspaceFolder}\\deps\\SFML-2.6.0\\lib"
  }

I also have this setup.bat script so I can do deps\setup when I need to use cli (cargo build --release);

SET SFML_INCLUDE_DIR=%cd%\deps\SFML-2.6.0\include
SET SFML_LIBS_DIR=%cd%\deps\SFML-2.6.0\lib

(Unfortunately it's still required to copy the DLLs but that's a thing you do once and less likely need to do later).

NuriYuri avatar Aug 23 '23 19:08 NuriYuri

I've been experimenting with techniques to statically link libstdc++ (and libgcc) on Linux on the vendored-sfml branch, but so far nothing worked. In particular, any form of -static-libgcc and -static-libstdc++ flags seem to get ignored. But if anyone manages to make it work, let me know.

crumblingstatue avatar Sep 23 '24 22:09 crumblingstatue