Compile error caused by case of filename extension
When the contents of TESTING.C are:
#include "stdio.h"
void main(void)
{
printf("\n%d\n", ( -0.25 < 0) ? 2 : 4);
}Upon trying to compile:
$ gcc -o TESTING TESTING.C TESTING.C:3: error: ‘::main’ must return ‘int’
Then I changed the file to:
#include "stdio.h"
int main(void)
{
printf("\n%d\n", ( -0.25 < 0) ? 2 : 4);
return 1;
}Then I got:
$ gcc -o TESTING TESTING.C /tmp/ccEnQk4o.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit status
But if I change the input file name extension to testing.c or even TESTING.c (small letters) no problems were got. Why is this?
Signature · 7 lines
Tux #395953 resides at http://samvit.org playing with KDE 3.51 on SUSE Linux 10.0 $ date [] CCE +2006-03-25 W12-6 UTC+0530 - To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi,
On Sat, 2006-03-25 at 13:33 +0530, Shriramana Sharma wrote:
[..]
Quoted 8 lines
$ gcc -o TESTING TESTING.C /tmp/ccEnQk4o.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit statusBut if I change the input file name extension to
testing.cor evenTESTING.c(small letters) no problems were got. Why is this?
From the man page of gcc(1):
file.cc
file.cp
file.cxx
file.cpp
file.CPP
file.c++
file.C
C++ source code which must be preprocessed. Note that in .cxx, the
last two letters must both be literally x. Likewise, .C refers to a literal capital C.
That means, gcc will consider a source file with name TESTING.C to be a C++ source code. Thus trying to include / link with some special libraries.
To compile your TESTING.C, use something like:
$ g++ -o TESTING TESTING.C
It 'll compile correctly.
Hope this helps.
Srinidhi.
Signature · 3 lines
ASCII ribbon campaign ( ) B S Srinidhi
- against HTML email X http://srinidhi.deeproot.co.in
& vCards / \ DeepRoot LinuxHi,
don't use void main() functions.. use int main instead. The c++ standard defines the return value of main being int, though compiler also support void.
In general int should be better since other applications could check for the return value if the application exited successfully or not..
Markus
Quoted 40 lines · B S Srinidhi
Hi,
On Sat, 2006-03-25 at 13:33 +0530, Shriramana Sharma wrote:
[..]Quoted 10 lines
$ gcc -o TESTING TESTING.C /tmp/ccEnQk4o.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit statusBut if I change the input file name extension to
testing.cor evenTESTING.c(small letters) no problems were got. Why is this?From the man page of gcc(1):
file.cc
file.cp
file.cxx
file.cpp
file.CPP
file.c++
file.C
C++ source code which must be preprocessed. Note that in .cxx, the
last two letters must both be literally x. Likewise, .C refers to a literal capital C.That means, gcc will consider a source file with name TESTING.C to be a C++ source code. Thus trying to include / link with some special libraries.
To compile your TESTING.C, use something like:
$ g++ -o TESTING TESTING.CIt 'll compile correctly.
Hope this helps.
Srinidhi.
--
Quoted 9 lines
ASCII ribbon campaign ( ) B S Srinidhi - against HTML email X http://srinidhi.deeproot.co.in & vCards / \ DeepRoot Linux-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
--
Markus Rechberger