gcc: How to install?

Hello,

pkg install lang/gcc. To install older versions, for example gcc 8, execute pkg install lang/gcc8.
This will not create the gcc symlinks so when you type gcc -v it will error. The lang/gcc package installs the symlinks for you but if you install lang/gcc8, you have to create the symlinks yourselves.
 
A few points:
  • First read these files:/usr/ports/Mk/bsd.gcc.mk and /usr/ports/Mk/Uses/compiler.mk.
  • Ports should request for specific version of GCC in its Makefile.
  • It is incorrect to set any USE_GCC in /etc/make.conf. e.g. USE_GCC=8.4.
  • You have to change ports' Makefile:
    Code:
    FAVORITE_COMPILER= gcc
    USE_GCC= 8.4
    USES += compiler
  • You can set to install the GCC compiler as /usr/bin/cc, /usr/bin/c++ and /usr/bin/cpp.
    • Refer to WITHOUT_CLANG_IS_CC and WITH_CLANG_IS_CC on sections on Refer to src.conf(5).
  • cc -v shows version of /usr/bin/cc.
    • /usr/bin/cc is a hard link. Run this command to find all hard-linked binaries:
      # find /usr/bin -inum `ls -i /usr/bin/cc | cut -d ' ' -f 1`
      Code:
      /usr/bin/clang++
      /usr/bin/cc
      /usr/bin/cpp
      /usr/bin/clang
      /usr/bin/c++
      /usr/bin/clang-cpp
 
To add to what vigole stated, DEFAULT_VERSIONS+= gcc=8 in /etc/make.conf is probably what you'd want if you wanted to build gcc8 and install symlinks to what gcc8 installs; the current default is actually gcc9. /usr/ports/Mk/bsd.default-versions.mk lists several other defaults.

While there's nothing stopping you from setting variables like GCC_DEFAULT directly in /etc/make.conf, DEFAULT_VERSIONS is apparently the correct method, and you can see that it looks cleaner:
Code:
## Old way
PYTHON_DEFAULT= 3.8
PYTHON3_DEFAULT= 3.8
WITH_BDB_VER=5
WITH_OPENSSL_PORT=yes
# Optionally, you specified the port name if you wanted to use an alternative to OpenSSL
OPENSSL_PORT= security/libressl

## New way
DEFAULT_VERSIONS+= bdb=5
DEFAULT_VERSIONS+= python=3.8 python3=3.8
DEFAULT_VERSIONS+= ssl=libressl

You can read more about DEFAULT_VERSIONS and view Mk/bsd.default-versions.mk to see an up-to-date list of ports that it works with since the wiki doesn't currently list them all.
 
  • Like
Reactions: a6h
Back
Top