• CONTEST ALERT - Experience the power of DDR5 memory with Kingston Click for details

Why is this program rejected by C++ compilers?

gopi_vbboy

Cyborg Agent
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:
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

Journeyman
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

Simply a DIGITian
Staff member
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.
 
OP
G

gopi_vbboy

Cyborg Agent
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:

 

doomgiver

Warframe
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
 
Top Bottom