I am curious as how to install the CC command line compiler for my uni C++ projects I am not interested in g++ or gcc or whatever I want to use CC exactly so I get the desired affect of when I use it in class, however I class we use CentOS so I dont know if this makes a difference

Dani AI

Generated

Short primer and practical options (clarifies 's question and ties into 's observation).

"CC" is ambiguous: many Linux distributions ship a generic C/C++ driver name that is managed by the alternatives system and commonly points at GCC; that is why saw a link to the system compiler. To match the classroom behavior it is important to first identify whether the lab’s "CC" is simply the distro's gcc/g++ or a vendor C++ driver (Solaris/Oracle-style CC) before changing anything. (manpages.debian.org)

Build tools and build systems pick compilers differently: traditional make uses CC for the C compiler and CXX for C++ (so setting CXX is the usual way to pick a C++ compiler for configure/make-based builds). Autoconf-style configure scripts also honor CXX/CC when present. If class materials invoke CC specifically as a program name, that is different from the environment-variable convention used by most build systems. (gnu.org)

Practical approaches on an Ubuntu desktop to reproduce a lab environment:

  • Install the distribution packages that provide a C/C++ toolchain (Ubuntu commonly uses the build-essential / compiler packages) or, on CentOS/RHEL, the "Development Tools" package group — these are the supported ways to get gcc/g++ on those distros. After installing, either rely on the distro-provided cc/c++ wrappers or explicitly set CXX when building to force a particular compiler. (discourse.ubuntu.com)

If the lab uses a vendor CC (for example Oracle Developer Studio’s CC), that driver has different flags and ABI behaviors; reproducing exact classroom output may require installing the same vendor compiler or creating a small wrapper named CC that invokes g++ with the same flags the lab uses. Installing the same vendor toolchain is the most faithful option when binary behavior matters. (docs.oracle.com)

Quick examples (adapt paths as needed):

# force builds that use the env var:
export CXX=/usr/bin/g++

# create a local 'CC' driver (local bin should be before /usr/bin in PATH):
ln -s /usr/bin/g++ /usr/local/bin/CC

Notes: prefer the distro packages rather than hand-copying compilers; avoid changing system files unless the behavior and version are confirmed.

Recommended Answers

All 3 Replies

Are you sure its not using gcc? Most distros alias 'cc' to 'gcc' which is probably what is happening here.

sk@sk:~$ which cc
/usr/bin/cc
sk@sk:~$ ls -al `which cc`
lrwxrwxrwx 1 root root 20 Oct 15  2004 /usr/bin/cc -> /etc/alternatives/cc
sk@sk:~$ ls -al /etc/alternatives/cc
lrwxrwxrwx 1 root root 12 Feb  1  2007 /etc/alternatives/cc -> /usr/bin/gcc
sk@sk:~$ which gcc
/usr/bin/gcc

In this case "cc" is a symlink to "/etc/alternatives/cc" which is a symlink to "/usr/bin/gcc".

What this means: cc=gcc.

Well how do I install gcc?

Well if you type gcc you will see this:

sk@svn:~$ gcc
The program 'gcc' can be found in the following packages:
 * gcc
 * pentium-builder
Try: sudo apt-get install <selected package>
-bash: gcc: command not found

So you should probably:

sk@svn:~$ sudo apt-get install gcc
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.