2007-03-01

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.


Commenting is disabled for this post.

Read more of Faux' blog