问题
Delphi documentation says that "Debug information [...] it does not affect the size or speed of the executable program."
However, when I activate Debug information (in Project Options -> Linker) my EXE goes from 1.8MB to 7MB. What am I doing wrong?
Note: I suppose that the 'Debug information' under 'Linking' is the same as 'Debug information' under 'Compiling' since they have the same compiler directive ( {$D} ).
回答1:
Your assumption is incorrect. Compiling with debug information means that the compiler generates DCUs with debug information. Linking with debug information means that the linker puts the debug info from the DCUs into the final binary instead of stripping it out, so of course that will make the binary a lot bigger.
Linking without debug info is usually OK, since the debugger can get at the debug info in the DCUs as long as it can find them. But if you need to debug your app in some scenario where the DCUs won't be available, you'll want the link option turned on.
回答2:
Adding debug information won't impact the code size (the code generated is the same with the option on or off, other options control code generation), but will impact the file size.
来源:https://stackoverflow.com/questions/6267246/debug-information-d-increases-the-size-of-my-exe-with-6mb