Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is this program erroneously rejected by three C++ compilers?
    text
    copied!<p>I am having some difficulty compiling a C++ program that I've written.</p> <p>This program is very simple and, to the best of my knowledge, conforms to all the rules set forth in the C++ Standard. I've read over the entirety of ISO/IEC 14882:2003 twice to be sure.</p> <p>The program is as follows:</p> <p><img src="https://i.stack.imgur.com/JQXWL.png" alt="enter image description here"></p> <p>Here is the output I received when trying to compile this program with Visual C++ 2010:</p> <pre><code>c:\dev&gt;cl /nologo helloworld.png cl : Command line warning D9024 : unrecognized source file type 'helloworld.png', object file assumed helloworld.png : fatal error LNK1107: invalid or corrupt file: cannot read at 0x5172 </code></pre> <p>Dismayed, I tried g++ 4.5.2, but it was equally unhelpful:</p> <pre><code>c:\dev&gt;g++ helloworld.png helloworld.png: file not recognized: File format not recognized collect2: ld returned 1 exit status </code></pre> <p>I figured that Clang (version 3.0 trunk 127530) must work, since it is so highly praised for its standards conformance. Unfortunately, it didn't even give me one of its pretty, highlighted error messages:</p> <pre><code>c:\dev&gt;clang++ helloworld.png helloworld.png: file not recognized: File format not recognized collect2: ld returned 1 exit status clang++: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation) </code></pre> <p>To be honest, I don't really know what any of these error message mean.</p> <p>Many other C++ programs have source files with a <em>.cpp</em> extension, so I thought perhaps I needed to rename my file. I changed its name to <em>helloworld.cpp</em>, but that didn't help. I think there is a very serious bug in Clang because when I tried using it to compile the renamed program, it flipped out, printed "84 warnings and 20 errors generated." and made my computer beep a lot!</p> <p>What have I done wrong here? Have I missed some critical part of the C++ Standard? Or are all three compilers really just so broken that they can't compile this simple program? </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload