Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

C 

File Size is pretty big

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;
}
Try striping the executable.
May you be given directions by software engineer document writers.
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
(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
(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?
May you be given directions by software engineer document writers.
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.
(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
Hello ,I compiled with vs2013 ,
Just copied your code ,
Reslut exe is 65kb.
Is the problem with the compiler you use ?
(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.
[Image: chain.png]
what is your compiler?? visual-studio has some properties that can help u. disable debug and enable optimization.
http://www.mingw.org/wiki/Large_executables
[Image: bitcoin.png] Be Nice For Once 15hVUVz7xA4kazHdk2BuErENGCskVwjYXP


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by sonnyJul 2, 2021 02:17 PM 0 223 Jul 2, 2021 02:17 PM
Last Post: sonny
[C#] by zxPhantomBladeJul 17, 2020 06:38 PM 3 157 Jul 17, 2020 06:38 PM
Last Post: Accord
[C] by SIM-3149568May 9, 2020 09:20 AM 3 171 May 9, 2020 09:20 AM
Last Post: 0xDEAD10CC