C++ DLL Dependency

I recently started learning coding in c++ after I learned (not too much experience) c. I have the code::blocks IDE and mingw compiler. I have seen that the compiled c executables are way smaller because they aren't DLL dependent (please correct me if I am wrong). So I was wondering if there was any way to make the compiled c++ executables not DLL dependent, as I have researched this and gotten no good answer.
Last edited on

GLLEES (1)
I recently started learning coding in c++ after I learned (not too much experience) c. I have the code::blocks IDE and mingw compiler. I have seen that the compiled c executables are way smaller because they aren't DLL dependent (please correct me if I am wrong). So I was wondering if there was any way to make the compiled c++ executables not DLL dependent, as I have researched this and gotten no good answer.



there is a concept 'static linkage' (embed the library into the executable program) and dynamic linkage (leave it in a .dll file) that could be an issue.
also note that c++ tools like to make debug builds by default, be sure you compiled it as release to get rid of that bloat in the executable file.
c++ does tend to be slightly larger than C when it compiles. visual studio has settings to favor smaller executable files vs faster vs other ideas. I do not know how many things you can tamper with using your tools.

how much difference are you seeing? The size of the executable file does not directly relate to the performance (could be that inline bloated the size but runs faster) but it is tangential to it as it does cost to read a larger file into memory and to swap the pages around and all that stuff. It is not something most people worry about in the modern world; are you working on an embedded project?

a typical homework/school program on g++ for me gives me a 150k .exe file on windows.
Last edited on
I do have the 'required' DLL Linked, so it works. The problem is that when I build it with the DLL's it is 822kb in size (working), while the one without DLL's is 17kb in size (not working). It would be fine, but I'm a file size nerd. Gatta squeeze the excess kb outa things.
Last edited on
you may find this or similar articles enlightening. Its all about the settings.

https://newbedev.com/gcc-c-hello-world-program-exe-is-500kb-big-when-compiled-on-windows-how-can-i-reduce-its-size

you may also play with visual studio. It uses its own compiler, and you have native on native... the OS and the compiler writers were at least at the same company, and probably shared some secrets that g++ and others may not know. I'd bet you can get it way down if you dig into the settings.
Like I said, c++ is going to be bigger than C. The iostream library is a clunky hog, and it shows in these exercises dramatically.
Last edited on
I took one of my toy programs that was 185KB from g++ on windows and did as much shrinking as I could with obvious settings to it in visual studio, getting a 56KB result. I do not hold that against g++; I don't know what flags it wants to make it smaller but I believe it probably could.
Last edited on
oooohhhhhh. iostream is retarded apparently. it takes up too much space.
iostream is bad.
Last edited on
until you use some object oriented code :)
iostream is 'bloated' because it is full of mostly useful features. My personal issues with it is that it is poorish at text to number and number to text work, and it relies on things that look like variables to control output. Its a personal grudge, and I don't expect many to agree.

again, 'big' executable isn't hurting anything except your own OCD or whatever until you get into the realm of very large -- many, many MB in size before it starts to really do much to you.
Topic archived. No new replies allowed.