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
Removing dependencies (Windows CRT) #1179
Comments
I personally don't think it is really worth the extra effort of maintenance + impact on readability etc. and the kind of people who are into that are usually also into not touching anything C++ related. That said, are there any specific function you are caring about? |
I have nearly re-created everything without the need of CRT, however there are a few errors remaining such as: After extensive google searching, I could not find what generates that. I could go ahead and define that myself, but I have no idea what it does. |
Really can't see why you need to remove the whole of the CRT, with modern compilers it can be quite hard. Don't know what the gain would be? |
@paulsapps
|
@nem0 is 100% right. I've created my entire game without the usage of CRT, which was allot of work, but it works perfectly fine. |
I'd like to bet if you measure the changes its not worth it, probably saves 500kb of exe size on static link. For dynamic link all modern OS'es have the UCRT already.. 3rd party things probably already use CRT, can't see why compile time would change, maybe link time but probably not by much. |
Anyway, this is a valid feature, although not valuable for most people. |
If anyone can do this, I'd even be willing to pay. |
What is CRT? |
I think |
@ocornut can you make like a test project for yourself without CRT so you can take a look? |
UCRT is windows 7+ so your 50% stats are wrong FYI. |
@paulsapps
|
Sorry being busy at the moment and when i'll get back on imgui I have other priorities, so can't prioritize that now :(
That symbol looks related to static variable initialization so if MSVC generates them it may have an option to not generate them. MS are probably not making your life easier with newer versions of MSVC.
(If you don't find the solution yoursef and want to contract-pay for it it's perhaps possible, tho If you made progress already it may be just a matter of fixing that thing)
|
@nem0 yes but: https://support.microsoft.com/en-us/help/2999226/update-for-universal-c-runtime-in-windows
I.e if the machine is patched (which most likely will be, especially because of wanna cry SMB exploit) it has UCRT. |
Yet. in real life I had a problem exactly with this. Thank god my client was benevolent at that time. |
ouch, no wonder wanna cry encrypted so many machines |
https://www.unknowncheats.me/forum/c-and-c/158088-thread-epoch.html Seems the main use case of no CRT is for hacks xD. To avoid it use compiler option: Some docs here: https://github.com/Microsoft/cpp-docs/blob/master/docs/build/reference/zc-threadsafeinit-thread-safe-local-static-initialization.md |
FYI the similar-but-unrelated-but-similar issue with Clang that someone else discussed with me was:
Errors such as:
Code
I haven't looked into that, but I presume that each compiler have some support for thread-friendly usage of static variables within functions, and probably those should be moved. |
@paulsapps thanks a bunch! Seems these hackers are useful sometimes. However now these are left: @ocornut the nice thing about clang is it tells you exactly where the issue is, msvc wants us to sweat.. :( (I'm thinking ImVector class is causing the first 4 errors) |
You want yourself to sweat :) Honestly I think you are just creating your own problems when doing this, but if you are going to do it you'd have an easier time using older versions of Visual Studio? |
@ocornut went back as far as VS 2008 and it generates the same errors. |
I'm super surprised that those CRT dependencies wouldn't have moved since 2008. If you solve the thing it would be useful to post a write-up (we could even make it a wiki entry?) for others who might be interested. |
Clearly the compiler was designed for those standard libraries, so it looks like few of those left-overs errors are related to explicit functions that imgui uses, more like generic code the compiler would emit for any C++ program. For constructor/destructor we only use placement new/delete which in theory remove dependency on |
For these last ones you need to reimplement exception handling (oh hey you can't) or disable exception handling (your only option really). You also need your own global operator new/delete since they are part of the CRT too. Plus any other part of the CRT your app uses. Also you need to disable compiler intrinsic functions.. because.. yup they are part of the CRT too. This will probably also make your app way slower. As will reimplementing new/delete with HeapAlloc/HeapFree. |
Closing this as we agreed that it won't be actively pursued by imgui to support compiling with zero CRT lib. If you manage to figure out ways forward feel free to post information as it may be useful to others. |
This is a complete guide on how to compile without CRT and keep code fast with intrinsics. Both 32 bit code and x64. I followed the guide successfully for my own project with msvc2017 and everything works just fine without crt now. Guide - How to avoid C/C++ runtime on Windows I didn't use imgui in this project though, so I don't know if there are any issues specifically related to imgui. |
@ocornut Do you think imgui will ever have a "No dependencies" version (basically without CRT linking)?
The text was updated successfully, but these errors were encountered: