Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
cc vs gcc
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
Bones McCracker
Veteran
Veteran


Joined: 14 Mar 2006
Posts: 1611
Location: U.S.A.

PostPosted: Wed Jan 09, 2013 7:20 pm    Post subject: cc vs gcc Reply with quote

What's the difference between cc and gcc? Neither is a link to the other (different inodes), but they both seem to be ways of invoking gcc and to have been created in close order by the gcc build process.

Searching the web I find a lot of misinformation (e.g., "one is a link to other"; "one is for ansi and the other for gnu"). I realize 'cc' is what the compiler is named in UNIX, but two separate files suggests there's a difference, yet the size is identical. The gcc manual doesn't seem to say anything about invoking gcc as 'cc', but I see this done frequently in various Makefiles.

What gives? Is it a copy, there just to satisfy a POSIX requirement that 'cc' actually be the compiler?
_________________
patrix_neo wrote:
The human thought: I cannot win.
The ratbrain in me : I can only go forward and that's it.
Back to top
View user's profile Send private message
wolfieh
n00b
n00b


Joined: 17 Nov 2009
Posts: 54

PostPosted: Wed Jan 09, 2013 9:02 pm    Post subject: Reply with quote

from what i know, they're front-ends. the actual compiler is "cc1plus"
Back to top
View user's profile Send private message
steveL
Watchman
Watchman


Joined: 13 Sep 2006
Posts: 5153
Location: The Peanut Gallery

PostPosted: Wed Jan 09, 2013 9:43 pm    Post subject: Reply with quote

'cc' is just the traditional unix command name that must be provided, which is why makefiles and configure systems default CC=cc. It was a LEGACY command in SUSv2 (POSIX 1997) which specified the c89 utility. Since 2001, POSIX requires the c99 command.

I'm not sure why they're different inodes and not a link to the same file: AFAIK gcc doesn't do anything different (you have to specify -std=c99 or the like to get a specific standard, if you're not using a path like c99.) You can see compare the predefines gcc produces like so:
Code:
touch empty.h
gcc -E -dM empty.h | sort > gcc.E_dM
cc -E -dM empty.h | sort > cc.E_dM
diff -u cc.E_dM gcc.E_dM
gcc -std=c99 -E -dM empty.h | sort > gcc-c99.E_dM
diff -u gcc.E_dM gcc-c99.E_dM

..and of course you see what the effects of flags like -march=native are within the code (this is useful if you want to detect your CPU for example). I can't recall how you get the exact command options gcc uses to drive the base utilities, maybe someone else will remember (something to do with the specfiles.)

You can use: gcc -E -dM - </dev/null as well, but I'm leary of that in general (eg you get an error output from make when you use it there, and iirc it doesn't work on older gcc versions.)
Back to top
View user's profile Send private message
Hypnos
Advocate
Advocate


Joined: 18 Jul 2002
Posts: 2889
Location: Omnipresent

PostPosted: Wed Jan 09, 2013 10:05 pm    Post subject: Re: cc vs gcc Reply with quote

BoneKracker wrote:
What gives? Is it a copy, there just to satisfy a POSIX requirement that 'cc' actually be the compiler?

It seems so -- "gcc" and "cc" have the same MD5 sum on my system. Poking around online, others have determined that argv[0] (the name of the executable) is only used in error output. This should be verifiable by browsing the gcc source code yourself.
_________________
Personal overlay | Simple backup scheme
Back to top
View user's profile Send private message
Bones McCracker
Veteran
Veteran


Joined: 14 Mar 2006
Posts: 1611
Location: U.S.A.

PostPosted: Wed Jan 09, 2013 11:32 pm    Post subject: Reply with quote

Thank you all. Interesting.
_________________
patrix_neo wrote:
The human thought: I cannot win.
The ratbrain in me : I can only go forward and that's it.
Back to top
View user's profile Send private message
Naib
Watchman
Watchman


Joined: 21 May 2004
Posts: 6051
Location: Removed by Neddy

PostPosted: Thu Jan 10, 2013 10:50 am    Post subject: Reply with quote

cc is the compliler from UNIX
gcc is the gnu c compiler.

cc and gcc have the same md5sum because they are the same executable.
Other distributions do: ln -s /usr/bin/gcc /usr/bin/cc

Because gentoo can have multiple gcc's installed in different slots another approach is needed.
GCC installs /usr/bin/gcc-4.5.4 gentoo's gcc-config then, for the selected profile copies this to /usr/bin/gcc and /usr/bin/cc

why copy and not a symlink? gcc-config is an old script. It probably could be updated such that /usr/bin/gcc --> /usr/bin/gcc-4.5.4 and /usr/bin/cc --> /usr/bin/gcc-4.5.4 (profile dependant)

Why keep cc around? old UNIX projects that are still flying around unmaintained which have make files calling cc. Do you try to resurect those projects, make them linux projects and update the make files OR just tweak the build system.

NOTE real CC and GCC are actually subtly different for ANSI C. CC cannot have a trailing carriage return iirc.
Back to top
View user's profile Send private message
Hypnos
Advocate
Advocate


Joined: 18 Jul 2002
Posts: 2889
Location: Omnipresent

PostPosted: Thu Jan 10, 2013 1:40 pm    Post subject: Reply with quote

Indeed, the executables /usr/bin/{cc,gcc} are from the sys-devel/gcc-config package. Source here. The wrapper calls the same GNU executable for "cc" and "gcc".

Naib wrote:
NOTE real CC and GCC are actually subtly different for ANSI C. CC cannot have a trailing carriage return iirc.

That's interesting -- does GNU compiler exhibit this behavior when called as "cc" ?
_________________
Personal overlay | Simple backup scheme
Back to top
View user's profile Send private message
Bones McCracker
Veteran
Veteran


Joined: 14 Mar 2006
Posts: 1611
Location: U.S.A.

PostPosted: Thu Jan 10, 2013 6:06 pm    Post subject: Reply with quote

Hi, Naib! :)

Okay, this confirms what I thought, there's no difference between calling gcc as 'gcc' or 'cc'. That was the main thing I wanted to confirm.

However, this still doesn't answer why we have two files (two copies of the binary wrapper, as it were), rather than a hard link or soft link to a single file. That's just a curiosity, though.
_________________
patrix_neo wrote:
The human thought: I cannot win.
The ratbrain in me : I can only go forward and that's it.
Back to top
View user's profile Send private message
steveL
Watchman
Watchman


Joined: 13 Sep 2006
Posts: 5153
Location: The Peanut Gallery

PostPosted: Thu Jan 10, 2013 11:50 pm    Post subject: Reply with quote

Naib wrote:
NOTE real CC and GCC are actually subtly different for ANSI C. CC cannot have a trailing carriage return iirc.

You might be thinking of the restriction that a C source file has to end in a newline, which is part of the C Standard. How a carriage return is interpreted is up to the input routines/libc, but on Unix you don't usually have any in any case.

iirc gcc warns you if your source file is not newline terminated, or at least non-blank non-terminated, certainly with -Wall.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum