4

I am learning C and came across cc in the bash shell i.e. whenever I make my source files I see this command.

Hence started to understand it,started with gcc --help but couldn't find cc option in the help. So started surfing the net, and came across this post. In the second answer it says cc is an environment variable and often points to /usr/bin/gcc on Linux systems.

I am using Linux distro and when I print return value from getenv("cc"), I am getting NULL. Why is this happening?

Community
  • 1
  • 1
Naresh
  • 369
  • 2
  • 11
  • try to run `env` on the shell you're invoking your C program with. Do you get that `cc` variable? CC is an automatic variable from gnu make: https://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html – Aif Aug 31 '16 at 16:46
  • 3
    No, it says CC is an environment variable. Not cc. – Thomas Padron-McCarthy Aug 31 '16 at 16:49

3 Answers3

3

cc is usually not an environment variable. There is commonly a symbolic link /usr/bin/cc which points at gcc.

aschepler
  • 70,891
  • 9
  • 107
  • 161
2

"cc" is a c compiler (executable), its not exposed as an environment variable ... getenv will print env variables

0

Quoting :

cc is a common name for a C compiler executable or driver. It is the default for the $(CC) make variable.


Because, as the ref states:

If the specified name cannot be found in the environment of the calling process, a null pointer shall be returned.


Moreover, if you run env on a terminal, will you see cc? Not really! That's why you get a NULL pointer. Since it doesn't seem to be an environment variable..


I believe that the cc you mention is something like this in your makefile:

CC=gcc

something usual in Makefiles.

gsamaras
  • 71,951
  • 46
  • 188
  • 305