I'm new to FreeBSD, coming from Linux and have always used gcc.
In FreeBSD so I can compile in C and C++ what should I use?
The canonic name for the system's C compiler has always been
cc
on any "unixy" system. It should always be present when the system
has a C compiler. If
cc
does not work on your Linux system, something is broken there.
FreeBSD uses LLVM's
clang
and not GNU's
gcc
to provide
cc
. In many cases,
cc
will actually be a symlink or hardlink.[*]
When you write some
Makefile
and want to be portable, always default to using
cc
, and additionally provide a way for the user to override it by setting the
CC
make variable.
---
[*] On FreeBSD, it's a hardlink, see
Code:
$ ls -li /usr/bin/clang
496856 -r-xr-xr-x 6 root wheel 94263896 19 März 11:38 /usr/bin/clang
$ ls -li /usr/bin/cc
496856 -r-xr-xr-x 6 root wheel 94263896 19 März 11:38 /usr/bin/cc
(same inode number)
edit: Indeed, what
SirDice said, many compilers are available from ports. But you
should always use the system's default/base compiler, unless there's some very specific need for a specific compiler and version, which is then typically outside the scope of the C language standard. Explicitly typing
gcc
on a Linux system is a bad habit (there
should be a
cc
as well invoking the very same compiler), and turns into a portability annoyance when used in Makefiles and similar for systems that don't use gcc ....
----
Yet another edit, I overlooked you also asked about C++. Well, basically the same. The canonic name is
c++
and should always work when a system default C++ compiler is installed. GCC's compiler is named
g++
, LLVM's compiler
clang++
, but don't use these names unless you mean specifically
that compiler.
And
SirDice,
cpp
is the canonic name for the C preprocessor (rarely invoked directly), so don't confuse that ?