Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSVC command-line option to remove debug information

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.

like image 540
AlainD Avatar asked Jan 17 '26 06:01

AlainD


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.

like image 186
dxiv Avatar answered Jan 19 '26 19:01

dxiv



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!