Monday 14 June 2010

C++ common pitfall

czz61240@LMPH8MF:~/testing123$ g++ -Wall a -o z
/usr/bin/ld:a: file format not recognized; treating as linker script
/usr/bin/ld:a:1: syntax error
collect2: ld returned 1 exit status

>>>>>>>>>>>>>> Because a does not have .c extension, should be a.c


czz61240@LMPH8MF:~/testing123$ gcc a.c -o z
a.c:3:20: error: iostream: No such file or directory
a.c:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘namespace’
a.c: In function ‘main’:
a.c:9: error: ‘cout’ undeclared (first use in this function)
a.c:9: error: (Each undeclared identifier is reported only once
a.c:9: error: for each function it appears in.)


>>>>>>>>>>>>>>> Because iostream (successor of iostream.h) is C++ header, so must use g++ compiler.

No comments:

Post a Comment