MSVC command-line option to remove debug information

Viewed 666

I have the following simple C++ program in a file called "hw.cpp":

#include <stdio.h>
int main(int argc, char* args[])
{
    printf("Hello, world!\n");
    return 0;
}

Compiling with gcc 9.3.0 (Ubuntu), gives the following results:

  • gcc -g0 hw.cpp -o hw.out (disable debug info) => size is 17k (same if -g0 is removed)
  • gcc -g3 hw.cpp -o hw.out (maximum debug info) => size is 44k

But the default compile for MSVC (cl version 19.26.28806) outputs a much bigger file:

  • cl hw.cpp /link /out:hw.exe => size is 101k

Why is the MSVC version so big? Is this related to debug information and how do is debug information disabled? The cl.exe compiler options don't have an obvious equivalent for the gcc -gN options.

1 Answers

These are the hw.exe sizes I am seeing for the combinations of static/dynamic linking of the C runtime vs. debug/release builds for a default 32b compile of your hw.cpp with VC++ 2019.

                   debug                 release
static      (cl /MTd)  279,040      (cl /MT)  101,888
dynamic     (cl /MDd)   10,240      (cl /MD)    8,192

The 32b release build cl /MD hw.cpp dynamically linked to VCRUNTIME140.DLL runtime has 8k. The big jump in size with /MT comes from statically linking the core C support, stream library etc.

Related