DIGIT-ARC read-only archive · snapshot: July 23, 2026

Why is this program rejected by C++ compilers?

14 posts · originally from https://geek.digit.in/community/threads/why-is-this-program-rejected-by-c-compilers.154929/

G
gopi_vbboy Original post #1
Apr 1, 2012 at 10:28 AM
I am having some difficulty compiling a C++ program that I've written.

This program is very simple and, to the best of my knowledge.

The program is as follows:
*i.stack.imgur.com/JQXWL.png

Here is the output I received when trying to compile this program with Visual C++ 2010:

Code:
c:\dev>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

Dismayed, I tried g++ 4.5.2, but it was equally unhelpful:
Code:
c:\dev>g++ helloworld.png
helloworld.png: file not recognized: File format not recognized
collect2: ld returned 1 exit status

To be honest, I don't really know what any of these error message mean.

Many other C++ programs have source files with a .cpp extension, so I thought perhaps I needed to rename my file. I changed its name to helloworld.cpp, but that didn't help.

What have I done wrong here? Have I missed some critical part of the C++ Standard? Or are all compilers really just so broken that they can't compile this simple program?
dead.night7
Apr 1, 2012 at 10:40 AM
1. Try to add a line after include iostream

using namespace std;

2. Try to remove std:: before cout<<

3. If your file named xyz.cpp

Write:
g++ xyz.cpp -o xyz
This will make a machine code, for running
Just type in
./xyz //(namely the machine code that you made by compiling just run it)

Basically I use gcc/g++ with linux
krishnandu.sarkar
Apr 1, 2012 at 10:56 AM
helloworld.png?? :O

C++ files extensions should be .cpp

How would C++ compilers recognize .png file..??

If you check the output of compilers, both of them clearly says "unrecognized source file type 'helloworld.png'" and "helloworld.png: file not recognized: File format not recognized"

Many other C++ programs have source files with a .cpp extension, so I thought perhaps I needed to rename my file. I changed its name to helloworld.cpp, but that didn't help.

What have I done wrong here? Have I missed some critical part of the C++ Standard? Or are all compilers really just so broken that they can't compile this simple program?

Sorry, I missed this part. Not many other, all the C++ files should have .cpp extension.

Well, just renaming a image file to cpp, it won't help, because internally information are not changed.

Write those lines in notepad, notepad++ or whatever IDE you use. and then save it with helloworld.cpp and then try to compile.
G
Apr 1, 2012 at 11:03 AM
1. Try to add a line after include iostream

using namespace std;

2. Try to remove std:: before cout<<

3. If your file named xyz.cpp

Write:
g++ xyz.cpp -o xyz
This will make a machine code, for running
Just type in
./xyz //(namely the machine code that you made by compiling just run it)

Basically I use gcc/g++ with linux


But what is wrong with my program?

You see another guy here also has same problem like me :
:mrgreen:

April Fool!
*stackoverflow.com/questions/5508110/why-is-this-program-erroneously-rejected-by-three-c-compilers
nbaztec
nbaztec #6
Apr 1, 2012 at 11:23 AM
You forgot to include
Code:
#include <pngcodec>

Here
*snag.gy/1SiBT.jpg
Gauravs90
Apr 1, 2012 at 11:35 AM
Aren't you making us april fool!!!!!
$$Lionking$$
May 2, 2012 at 10:58 AM
HAHAHAHAHA!!!!!!!!!!!!!!

Kickkaaaaaaaaasssssssssssss!!!!!!!!!!!!!!!!!!!!1 :D
doomgiver
doomgiver #11
May 2, 2012 at 11:36 PM
could someone explain me the significance?
sure its a png file, but i dont get it why its a joke?
$$Lionking$$
May 2, 2012 at 11:48 PM
^ coz u have to write ur code in a text editor not paint brush! :p :D

ROFLCOPTER! :D
doomgiver
doomgiver #13
May 2, 2012 at 11:54 PM
i still dont find it funny.
passing a drawing to a compiler.

bad joke falls flat on its face :/

no wonder i missed it on 1st april
$$Lionking$$
May 3, 2012 at 12:23 AM
doomgiver... - hey nbaztec has updated with the solution!!! :p :D