tags:

views:

190

answers:

5

I have looked into the binaries produced by MSVC 2010 from my source code, and saw everything being filled with "junk". (Not the kind of junk that calls itself "my code")

I don't know how to explain, but my executables are being added too much unnecessary information, like:

  • Lots of Microsoft default error messages, I don't want them
  • XML schema settings (Why!?)
  • Other things not important for the execution of the main program

How can I stop MSVC doing this? Do I have to switch to GCC?

In all other programs (written in C++ too, from Word processors to games), this junk simply doesn't exist.

A: 

Other then switching to another compiler you can try compiler optimizations. Enable "function-level linking", "whole program optimizations" and elimination of unused data/code - most likely some of the code/data you don't like is actually not used and the linker could simply eliminate it.

sharptooth
I already did, but that didn't seem to solve the problem. There just aren't any project options for "do-not-mess-up-my-executable".
sub
@sub: Could you cite the command lines for the compiler and linker? They can be seen in the "comman line" sections of "C++" and "Linker" sections of the project.
sharptooth
+7  A: 

Lots of Microsoft default error messages, I don't want them

because you are using the C/C++ runtime (eg, malloc,printf,strcpy)

XML schema settings (Why!?)

So you get appropriate UAC (User Account Control) handling, up-to-date comctrl (Which is required for Windows themed controls to apply to your program), and to specify which msvcrt.dll to use.

edit: another feature that causes extra code, is VC's placement of a cookie in the stack and the related code to validate the cookie. see http://blogs.msdn.com/michael_howard/archive/2007/04/03/hardening-stack-based-buffer-overrun-detection-in-vc-2005-sp1.aspx for more info.

steelbytes
If most other executables don't need that and G++ doesn't even have it, why should I need it?
sub
you don't have to have these two things, i was just explaining why it put them there. you can turn of the manifest stuff int he opts, and you can define your own entry point and not use any of the c runtime, and you will get what you are asking for.
steelbytes
eg, http://www.benshoof.org/blog/small-programs/
steelbytes
+1  A: 

Link against libctiny. I've built 4kB EXEs that way.

MSalters
+1  A: 

Why do you assume they aren't important to the running of the application? What if they are? What are the 'other things' you mention as well?

If you removed the default error messages, a user might legitimately encounter that error, then there would be no message displayed to them, leaving them even worse off. (As another answer mentioned these are most likely from the C runtime library, and most likely your program does need that!)

The XML could be an embedded manifest that specifies some of the DLL requirements. This helps prevent the 'DLL hell' situation where programs depend on different versions of a DLL with the same name. Amongst other things, it specifies the precise version information of DLLs, so you never run in to that ugly situation. Again, this seems to be something you would want.

The libraries and compiler settings for most C++ compilers will most likely add "junk" (I'd just call it library data) because of all the useful features they provide, saving you from having to solve those problems all over again yourself. If you still don't like any of that - stop using compilers, and start using assembler. Then you can specify exactly what is and isn't in the final compiled program, but you'll probably end up reinventing the wheel...

AshleysBrain
A: 

What you're seeing is not "junk".

Lots of Microsoft default error messages, I don't want them

Presumably you do want to use the libraries you're linking to, or you wouldn't be linking to them.

XML schema settings (Why!?)

That XML is your application's manifest. Why is it there? Because you asked the linker to add it. Take a look at the command line that you're passing to the linker. It will included the /MANIFEST and /MANIFESTFILE parameters.

Other things not important for the execution of the main program

If you don't know what they are, how do you know they're not important?

Joe Gauterin