LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-18-2011, 02:23 PM   #1
ssvirdi
Member
 
Registered: Apr 2009
Location: Ludhiana, Punjab, India.
Distribution: Ubuntu
Posts: 45

Rep: Reputation: 15
GCC compiler error while compiling *.c file


Dear Friends,

I write a program in C i.e. Hello.C

When I try to compile it by giving the following command

$ cc Hello.C
oR
$ gcc Hello.C

I always got this error

cc HELLO.C /tmp/ccB6cpfR.o: (.eh_frame+0x12): undefined reference to `__gxx_personality_v0' collect2: ld returned 1 exit status

Please help me to get out of it. Thanks
 
Old 11-18-2011, 03:48 PM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 2,230

Rep: Reputation: 605Reputation: 605Reputation: 605Reputation: 605Reputation: 605Reputation: 605
I guess the compiler thinks your source is C++,
try the same thing with lowercase filename: hello.c

Last edited by NevemTeve; 11-18-2011 at 03:50 PM.
 
1 members found this post helpful.
Old 11-18-2011, 04:01 PM   #3
johnsfine
Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,203

Rep: Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140Reputation: 1140
Quote:
Originally Posted by NevemTeve View Post
compiler thinks your source is C++,
I never knew that before (.C is treated as .cpp not as .c) but I both tested it and looked it up and you are correct.

ssvirdi, if you have some reason to want to keep the name Hello.C instead of changing it to Hello.c you could compile it with
gcc -xc Hello.C

The -xc option tells gcc the type of the input file is "c". If it knows the type already, it doesn't decide the type based on the extension (the .C).

The confusing error message you got is because the gcc command invokes the linker for a .c program regardless of the type of the input file. So your .C file is compiled as a C++ module but linked as a .c program, resulting in that link time error.

That behavior must seem silly when operating on just one input file. But gcc can compile and link multiple files in one command including mixed language programs. So this behavior that seems silly with one input file makes sense for more complicated commands.

Last edited by johnsfine; 11-18-2011 at 04:09 PM.
 
1 members found this post helpful.
Old 11-24-2011, 11:28 PM   #4
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,646
Blog Entries: 29

Rep: Reputation: 907Reputation: 907Reputation: 907Reputation: 907Reputation: 907Reputation: 907Reputation: 907Reputation: 907
The "case" doesn't make any difference on gcc version 4.5.0 .
I just tried that with a file h.C, there weren't any problems
shown.
 
1 members found this post helpful.
Old 11-25-2011, 02:17 AM   #5
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 2,230

Rep: Reputation: 605Reputation: 605Reputation: 605Reputation: 605Reputation: 605Reputation: 605
But with gcc-4.3.2 it can be reproduced easily:

Code:
$ gcc hello.C -o hello
/tmp/cceGJBdd.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

$ gcc hello.C -o hello -lstdc++
(works)

$ g++ hello.C -o hello
(works)

$ ln -s hello.C hello.c
$ gcc hello.c -o hello
(works)
 
1 members found this post helpful.
Old 11-25-2011, 02:20 AM   #6
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,646
Blog Entries: 29

Rep: Reputation: 907Reputation: 907Reputation: 907Reputation: 907Reputation: 907Reputation: 907Reputation: 907Reputation: 907
so, the crux is to shift to the newer gcc version.
 
Old 11-25-2011, 02:36 AM   #7
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 2,230

Rep: Reputation: 605Reputation: 605Reputation: 605Reputation: 605Reputation: 605Reputation: 605
Another option (if you are not root-user, for example) is following the standard: the extension is .c for C-language, not .C
 
Old 11-25-2011, 08:24 AM   #8
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714
Quote:
Originally Posted by NevemTeve View Post
Another option (if you are not root-user, for example) is following the standard: the extension is .c for C-language, not .C
Why is is only an option when you are not root?

The proper solution is to use a lowercase ".c" extension. Uppercase ".C" means C++, so don't use it for C source code.
 
Old 11-25-2011, 03:31 PM   #9
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by NevemTeve View Post
Another option (if you are not root-user, for example) is following the standard: the extension is .c for C-language, not .C
What does the issue have to do with (not) being 'root' ?
 
Old 11-25-2011, 10:06 PM   #10
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 2,230

Rep: Reputation: 605Reputation: 605Reputation: 605Reputation: 605Reputation: 605Reputation: 605
(If you aren't superuser, then you are not supposed to install new versions of gcc, but you can still follow the naming standards and use the extension .c for C-language.)
 
Old 11-26-2011, 12:10 PM   #11
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by NevemTeve View Post
... If you aren't superuser, then you are not supposed to install new versions of gcc ...
Huh ?

I am routinely compiling from source not as 'root' user more than 370 targets and install them in a non-system directory of mt liking. Even though it's my personal machine and I have root access.

But what does it have to do with a wrong file extension in the first place ?
 
Old 11-26-2011, 12:13 PM   #12
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714
Quote:
Originally Posted by NevemTeve View Post
(If you aren't superuser, then you are not supposed to install new versions of gcc, but you can still follow the naming standards and use the extension .c for C-language.)
But if you are superuser, you should still change it to ".c" instead of ".C", because ".C" is the wrong extension for C code.
 
1 members found this post helpful.
Old 11-26-2011, 12:24 PM   #13
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 2,230

Rep: Reputation: 605Reputation: 605Reputation: 605Reputation: 605Reputation: 605Reputation: 605
(I don't think we should continue this argumentation, because basically we all suggest the same thing: using the correct file-extension.)
 
2 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] gcc compiler is not compiling old C Programming files beacuse of timestamp issue aanand0 Linux - Newbie 15 11-23-2010 06:58 AM
Compiling gcc without compiler? davuuud Linux - Software 6 02-03-2009 11:16 AM
compiling x64 application from ubuntu x86 using gcc compiler samitpmc Programming 9 07-21-2008 04:53 AM
GCC compiler giving syntax error before 'double' error dragonmint Programming 2 06-02-2007 02:07 PM


All times are GMT -5. The time now is 02:34 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration