March 1st 2007 09:00 pm

cl /out:filename.exe

I was minorly confused today as to why all of my lovely compiled programs were disappearing and, instead, I was left with some empty files called ut.

For example, a test C++ file:
echo int main(){} > empty.cpp

Compile it:
>cl empty.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.762 for 80x86

Copyright (C) Microsoft Corporation. All rights reserved.

empty.cpp
Microsoft (R) Incremental Linker Version 8.00.50727.762
Copyright (C) Microsoft Corporation. All rights reserved.

/out:empty.exe
empty.obj

As it clearly says, this /out:puts to “empty.exe”. Okay, I don’t want it to output to “empty.exe”, I want it to be called “full.exe”. So, I add /out:full.exe to my build script (along with all the normal junk like /MD and /nologo), and the output is now:

C:\Desktop>cl /nologo empty.cpp /out:full.exe
cl : Command line warning D9035 : option 'o' has been deprecated and will be removed in a future release
empty.cpp

Curious, but only a warning, let’s ignore it.

..and full.exe doesn’t exist. Neither does empty.exe. There’s just this empty, zero-byte (according to Explorer) file called “ut”.

What’s happening, and what’s not immediately obvious if you don’t read boring warnings, is that the compiler it outputting (/ofilename to write the output to filename) to “ut:wrong.exe”, which is the NTFS alternate data stream called “wrong.exe”. Woops.

For reference, the message comes from the linker, not the compiler, which does use /out:filename, and the non-deprecated version of /o for the compiler is /Fefilename. Much clearer and easier to remember. Not.

3 Comments »

3 Responses to “cl /out:filename.exe”

  1. mulletron on 02 Mar 2007 at 10:35 am #

    USE RETURN STATEMENTS.

  2. Faux on 02 Mar 2007 at 2:42 pm #

    mulletron: A missing return statement on the end of an int main() {.. block is defined behaviour (it returns zero), unlike falling off the end of any other function (except void).

    Whether or not it’s good style is a different question. :)

  3. Fred on 02 Mar 2007 at 4:01 pm #

    You’re doing it wrong!!!!!

Trackback URI | Comments RSS

Leave a Reply

Spam Protection by WP-SpamFree

« | »