Hack Forums
[C] File Size is pretty big - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C] File Size is pretty big (/showthread.php?tid=6092437)



File Size is pretty big - PhantomBlade - Jul 4, 2020

Hello, i have this simple program, which is the default main.cpp in C++.
When it compiles to an exe its 2MB big, why is that so? Shouldn't it be like 60kb or something like that?

#include <iostream>

using namespace std;

int main()
{
cout << "Hello world!" << endl;
return 0;
}


RE: File Size is pretty big - saltycracker - Jul 4, 2020

Try striping the executable.


RE: File Size is pretty big - zer0kit - Jul 4, 2020

move to pure C or forget about reduced file sizes. std in c++ is a big pile of dependencies.

move to C

if you want to have even lower file sizes in C, remove CRT


#pragma comment(linker,"/ENTRY:myentry")


void myentry() {


}

result is having 4 to 10 kb sizes depending on amount of code. the only limitation is no CRT


RE: File Size is pretty big - PhantomBlade - Jul 4, 2020

(Jul 4, 2020 03:12 PM)zer0kit Wrote:  move to pure C or forget about reduced file sizes. std in c++ is a big pile of dependencies.

move to C

if you want to have even lower file sizes in C, remove CRT


#pragma comment(linker,"/ENTRY:myentry")


void myentry() {

 
}

result is having 4 to 10 kb sizes depending on amount of code. the only limitation is no CRT

Alright thank you


RE: File Size is pretty big - saltycracker - Jul 5, 2020

(Jul 4, 2020 11:49 AM)PhantomBlade Wrote:  Hello, i have this simple program, which is the default main.cpp in C++.
When it compiles to an exe its 2MB big, why is that so? Shouldn't it be like 60kb or something like that?

#include <iostream>

using namespace std;

int main()
{
   cout << "Hello world!" << endl;
   return 0;
}

Well, how are you compiling it?


RE: File Size is pretty big - incognito04 - Jul 5, 2020

Firstly, Turn on optimisations. You're most likely statically linking CRT for a file size that big so make sure your compiler is dynamically linking it.


RE: File Size is pretty big - PhantomBlade - Jul 5, 2020

(Jul 5, 2020 12:42 AM)saltycracker Wrote:  Well, how are you compiling it?

Im using the Codeblocks IDE for compiling, i think it uses mingw32 if im not mistaking


RE: File Size is pretty big - twineditor - Jul 5, 2020

Hello ,I compiled with vs2013 ,
Just copied your code ,
Reslut exe is 65kb.
Is the problem with the compiler you use ?


RE: File Size is pretty big - Sajuuk - Jul 5, 2020

(Jul 5, 2020 02:36 AM)PhantomBlade Wrote:  Im using the Codeblocks IDE for compiling, i think it uses mingw32 if im not mistaking

If GCC fully supports pragma comments now, I'm unaware of it. That that's nothing to do with the file size. Like mentioned above, you've probably got a linker setting which forces static linking of some or all associated libraries. Cramming that code into the one executable causes the file size spike. Compile from command line and pass an argument which forces dynamic linking for all associated libraries. In the case an error is returned (solely from the linker), only specify the libraries which are required to be linked dynamically. That's what I'd expect the cause to be, though it is a really weird situation from my understanding.


RE: File Size is pretty big - greasyAlessandra - Jul 11, 2020

what is your compiler?? visual-studio has some properties that can help u. disable debug and enable optimization.


RE: File Size is pretty big - HFDone - Jul 11, 2020

http://www.mingw.org/wiki/Large_executables