-
February 7th, 2010, 03:16 AM
#1
Why is my release exe 32 kb with only 14 lines of code?
Code:
#include < windows.h >
#include < string >
using namespace std;
void alert( const string& title, const string& message )
{
MessageBox( NULL, message.c_str(), title.c_str(), MB_OK | MB_ICONINFORMATION );
}
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
{
alert("Okay", "Working!");
return 0;
}
I just downgraded from MSVC++2008, which had my release exe 33kb with around 1000 or more lines of code, Im trying to learn how to use MSVC++6.0 and its giving me such a hard time with everything, I chose active config to release and hit build, and the exe in the folder is 32 kb with only this.
Edit: Apparently 2008 strips unused functions and discards code and things from header files, any way to do this in 2006? Should I try mingw for stripping?
Last edited by Craisins; February 7th, 2010 at 05:48 AM.
-
February 7th, 2010, 09:28 AM
#2
Re: Why is my release exe 32 kb with only 14 lines of code?
Is that 32K a debug build ? or a release build ?
VC2008 is a bit more aggressive in stripping out unused parts as opposed to VC6. Particularly when dealing with templates.
In this case, using the string class, this is probably dragging in the entire string class including the somewhat expensive formatting functions.
-
February 7th, 2010, 10:26 AM
#3
Re: Why is my release exe 32 kb with only 14 lines of code?
Debug is much bigger and release is around 32kb. What can be done to get VC2008 style cleanup?
Only reason I switched to VC6 is because VC2008 required some computers to have MSVC90.dll as a runtime library and is very annoying to the end user to have to install that, so I chose VC6. I wish 2008 had a way to build exe as VC6 does however.
-
February 7th, 2010, 11:31 AM
#4
Re: Why is my release exe 32 kb with only 14 lines of code?
Originally Posted by Craisins
Only reason I switched to VC6 is because VC2008 required some computers to have MSVC90.dll as a runtime library and is very annoying to the end user to have to install that, so I chose VC6.
It is a one time install, and since it is redistributable you should be able to make it part of your installer, if I am not wrong.
-
February 7th, 2010, 02:03 PM
#5
Re: Why is my release exe 32 kb with only 14 lines of code?
If the .exe filesize is a issue you could take a look at UPX.
-
February 7th, 2010, 08:18 PM
#6
Re: Why is my release exe 32 kb with only 14 lines of code?
Installer? It's just a standalone exe that uses messagebox. UPX works great but honestly a messagebox code shouldn't end up 16kb after UPXing. Hopefully when my program gets larger the filesize evens out.
-
February 8th, 2010, 01:18 AM
#7
Re: Why is my release exe 32 kb with only 14 lines of code?
You should check your project settings, may be something like debug info etc is on and is causing addition to size.
Regards,
Ramkrishna Pawar
-
February 8th, 2010, 02:09 AM
#8
Re: Why is my release exe 32 kb with only 14 lines of code?
If you set your VS2008 project to link the runtime library statically, then the DLL should not be required (but the exe size may be slightly larger).
-
February 8th, 2010, 03:35 AM
#9
Re: Why is my release exe 32 kb with only 14 lines of code?
Im in VC6.0 now, not using 2008 anymore.
-
February 8th, 2010, 07:15 AM
#10
Re: Why is my release exe 32 kb with only 14 lines of code?
Originally Posted by Craisins
Im in VC6.0 now, not using 2008 anymore.
Are you aware that MSVC6 is pre-standard?
-
February 8th, 2010, 10:34 AM
#11
Re: Why is my release exe 32 kb with only 14 lines of code?
Should I try mingw for stripping?
I have tested your program with dev-cpp and mingw.
With the default options, size of exe is 102 kb.
With options set for optimizations, size of exe is 49 kb.
With arrays of characters instead of strings, size of exe is 6kb (6144 bytes).
Code:
#include <windows.h>
void alert(char *title, char *message)
{
MessageBox( NULL, message, title, MB_OK | MB_ICONINFORMATION );
}
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )
{
alert("Okay", "Working!");
return 0;
}
-
February 8th, 2010, 11:00 AM
#12
Re: Why is my release exe 32 kb with only 14 lines of code?
Originally Posted by Craisins
Im in VC6.0 now, not using 2008 anymore.
....but, VC6 is the devil.
Well, at least it has enough problems that I'd advise choosing 2005 over it if you really *can't* use VC2008 for some reason. Personally, I think you haven't sufficiently explored its options yet.
-
February 8th, 2010, 11:22 AM
#13
Re: Why is my release exe 32 kb with only 14 lines of code?
Originally Posted by Craisins
Im in VC6.0 now, not using 2008 anymore.
VC 6.0 -- a compiler that is:
1) Unsupported by Microsoft, and truthfully a dwindling number of people here use it regularly.
2) Over 10 years old, therefore non-ANSI compliant
3) Compiles buggy C++ code, and fails to compile legitimate ANSI C++ code (this is related to item 2).
Here is an example of the problem, and it was brought up in a thread a few weeks ago.
Visual C++ 6.0 will compile broken code -- code that will not work with any later version of Visual C++, as well as any ANSI compiler. The problem is that the broken code that it compiles can be very pervasive -- especially the invalid for-loop scope that 6.0 uses. A poster had a program written in Visual C++ 6.0, and none of us could get the code to compile, since we are all using modern ANSI C++ compilers. There were literally hundreds of errors when compiled using a later version of Visual Studio.
Practically speaking, VC 6.0 should only be used for legacy applications that were already built with 6.0 way back when, and for some reason, those apps were never upgraded so that they were built with a later version of Visual Studio. New apps shouldn't be created with VC 6.0.
Many companies that used to build libraries using VC 6.0 have dropped support for it -- because it is not an industrial strength compiler for this day and age, maybe 12 or so years ago it was state of the art, but not now. Failure to compile templated code, and even legitimate non-templated ANSI C++ code is the reason why.
Regards,
Paul McKenzie
-
February 8th, 2010, 11:47 AM
#14
Re: Why is my release exe 32 kb with only 14 lines of code?
Originally Posted by Craisins
Installer? It's just a standalone exe that uses messagebox. UPX works great but honestly a messagebox code shouldn't end up 16kb after UPXing. Hopefully when my program gets larger the filesize evens out.
it is NOT the messagebox. MessageBox is a call tot he Windows API so it shouldn't even add any extra code other than the necessary framework to get the DLL loaded and the function imported.
The problem here is the use of the string class.
VC6 library design is know to be somewhat sloppy, and just creating a single string and not even using it other than the creation, drags the whole class tree and everything that class uses into your exe.
-> remove/comment out the alert function and the call to alert. And compile, you should get an exe somewhere 4-8K, even with VC6.
If exe size is important to you, then you need to be concerned about what classes you are importing. Write your own simple string class if you have to.
You can use an exe compresion tool, but know that this typically makes the exe smaller, but has a negative impact on actual memory used and the swap file since it ends up having the entire code and static data part of your exe loaded into private comitted data rather than shared/mapped memory space.
If you are worried about the MFC dll. you can link to MFC statically. This will make your exe larger, but it'll still be smaller than the size of your exe+dll it makes your distribution smaller and easier at the cost of more memory used.
-
February 8th, 2010, 12:54 PM
#15
Re: Why is my release exe 32 kb with only 14 lines of code?
Be a professional - write an installer (and don't write software with a 12 year old, non-compliant compiler).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|