how do i build gcc on a mac? - c++

I'd like to build the latest version of gcc on a mac. I have the latest xcode but I'm looking for some of the c++0x features that are in more recent versions (the lambda functions, etc).
Are there any good step-by-step tutorials on doing this?

You should look at the Homebrew project.
Homebrew allows you to do things like this:
brew install gcc
Mac homebrew installation instructions are available here.

Add GCC support to a fresh Xcode 4.2 installation using this homebrew formula:
brew install https://raw.github.com/Homebrew/homebrew-dupes/master/apple-gcc42.rb
Upgrading from Xcode 4.1 doesn't drop existing GCC support, so this formula is only useful if you're working with a fresh 4.2+ installation.

One option is to install MacPorts and install the gcc46 package:
sudo port install gcc46
Another option is to download the source code and build it as follows:
tar xzvf gcc-4.6.0.tar.gz
cd gcc-4.6.0
./configure
make
Note that GCC 4.6.0 requires as prerequisites GMP 4.2+, MPFR 2.3.1+, and MPC 0.8.0+. If ./configure fails, it's probably because you're missing one of these (though it should give you a helpful error message in any case).
Building will take a while—likely several hours, depending on your hardware.

I would suggest building it yourself (Adam details how to do so). This will give you fine control on where to install and all the options you want to select. My experience from having multiple versions of gcc is that, if care is not taken apple's version of gcc can be damaged.
To speed up gcc installation you might want to look at --enable-languages option. If there are languages you don't need installed with the new gcc then you may not want to select them.

Related

install llvm binaries without version number

When I install llvm using command
bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)"
The binaries that get installed looks like following
All the binaries have version number. For e.g. llvm-objdump-15.
But the tools I use are looking for llvm-objdump, while installer installed it as llvm-objdump-15. I can create a symbolic link with name llvm-obdump, but I want to know how to install it correctly and not have version numbers in all these binaries?
I fixed it by using apt-get install
sudo apt-get install clang-format clang-tidy clang-tools clang clangd libc++-dev libc++1 libc++abi-dev libc++abi1 libclang-dev libclang1 liblldb-dev libllvm-ocaml-dev libomp-dev libomp5 lld lldb llvm-dev llvm-runtime llvm python3-clang
It did install an older version, but it was fine for my needs
The names without version numbers are controlled by the llvm-defaults package on your distribution. It picks a specific version to make the default, and only that one has un-versioned symlinks installed into the system PATH.
As a consequence, on Debian based systems only one version (controlled by the distro) is going to be available there and it may not be the one from https://apt.llvm.org/. On these systems, the recommended way to use a specific version is to add the suffix.
If you can't do that, you should install the distro-provided version using the normal process rather than the versions on https://apt.llvm.org/.
To read more details about how all of this works, you can check out the documentation for the llvm-defaults package set here: https://salsa.debian.org/pkg-llvm-team/llvm-defaults/-/blob/experimental/debian/README.Debian

Install Boost with GCC on MacOS [duplicate]

I've installed gcc-4.6 using the homebrew-alternatives gcc formula, but I can't seem to get it to use that GCC to install other formulas. Specifically Open-MPI and boost.
Does anyone know how to make Homebrew use this new compiler?
Thanks!
It looks like the latest versions of Homebrew now support the HOMEBREW_CC and HOMEBREW_CXX environment variables.
So now you can do the following:
$ HOMEBREW_CC=gcc-4.2 HOMEBREW_CXX=g++-4.2 brew install ice
Homebrew can't adapt to other versions of gcc using command line options. You can easily override the older compiler, though, if you edit the open-mpi and boost formula. For example, you can add a few commands after the "def install" in open-mpi.rb:
def install
# Force compilation with gcc-4.6
ENV['CC'] = '/usr/local/bin/gcc-4.6'
ENV['LD'] = '/usr/local/bin/gcc-4.6'
ENV['CXX'] = '/usr/local/bin/g++-4.6'
# Compiler complains about link compatibility with FORTRAN otherwise
ENV.delete('CFLAGS')
ENV.delete('CXXFLAGS')
That worked for me on Lion. Good luck.
These answers are all fairly old now. It seems that recent versions of homebrew have a '--cc' option that enables you to select the c compiler to use. For example
brew install --cc=gcc-6 <package-name>
will install using the brew version of gcc
From their wiki it sounds like they don't support other compilers:
Installing a custom version of GCC or autotools into the $PATH has the potential to break lots of compiles. So we stick to the Apple-provided compilers.

Install older gcc/g++ versions in CentOS 8

I've been struggling with this for the past 2h. In CentOS 8 I can't find the devtoolset packages to install older gcc/g++ versions. There is no longer a scl repo for CentOS 8. I need gcc/g++ 4.9x installed along the current gcc/g++ 8.x and I need to be able to switch between the two. This was extremely easy to set up in Ubuntu, not the case in CentOS and the documentation is non-existent or I had trouble finding it.
If you wish to install an older gcc than the distro provides, you will need to compile it for source.
There is some guidance below on how to download and build an old GCC
https://bytefreaks.net/gnulinux/downgrade-gcc-on-centos-7-0-64bit-to-version-4-8-2
Found a solid path that has automated compiling and packaging gcc, as well as a guide:
Guide:
https://bobsteagall.com/2017/12/30/gcc-builder/
Github repo:
https://github.com/BobSteagall/gcc-builder
I won't copy paste what's in this person's guide as they deserve the credit. However, here's a summary of the steps:
Install your prereqs (rpm build tools, devtools for bootstrapping your environment).
Clone the repo.
Checkout a branch in the repo like the major version of GCC you want (e.g. gcc7).
In the repo, edit gcc-build-vars.sh such that it points to a version of GCC you want from http://gnu.mirror.constant.com/gcc/.
Perform the build with: ./build-gcc.sh -T | tee build.log.
Stage it: ./stage-gcc.sh.
Package it: (./pack-gcc.sh or ./make-gcc-rpm.sh -v).

mingw without g++ compiler

i am new to linux and I have the following question:
I am trying to install MINGW in Ubuntu.
I ran the command:
sudo apt-get install mingw-w64
It was installed, and if i put the command gcc it runs ok. The problem is g++ command does not work. I guess it is because i don't have the c++ compiler (as I read in similar questions in stackoverflow).
I read too that you can use the next command:
mingw-get install g++
but i don't have the executable program for this command.
My question is, how can I install that executable? or is there another way to update my mingw so I can use the g++ compiler?
Hope I have explained myself correctly. Thank you for any help I receive.
mingw-get is a windows specific package manager, it is not needed when you use a native linux package manager such as APT.
Installing package mingw-w64 depends on package g++-mingw-w64, which depends on g++-mingw-w64-i686 and g++-mingw-w64-x86-64.
These packages install the mingw cross compilers as
/usr/bin/x86_64-w64-mingw32-g++-posix
/usr/bin/x86_64-w64-mingw32-g++-win32
/usr/bin/i686-w64-mingw32-g++-posix
/usr/bin/i686-w64-mingw32-g++-win32
Older versions of mingw cross compiler shipped /usr/bin/i586-mingw32msvc-c++, which is replaced by i686-w64-mingw32-c++-win32
You can usually use this toolchain in a project by running ./configure CXX=i686-w64-mingw32-c++-win32 or make CXX=i686-w64-mingw32-c++-win32
Note: the above description is correct for the most recent toolchain in Debian unstable. It may need some minor tweaking for older systems.

How to use multiple versions of GCC

We have a new application that requires glibc 2.4 (from gcc 4.1). The machine we have runs on has gcc 3.4.6. We can not upgrade, and the application must be run on this machine.
We installed gcc 4.1, however, when it comes to compile time it is using all the includes, etc, from 3.4.6.
How do we get around this?
Any suggestions on using 4.1 for just this application?
Refer "How to install multiple versions of GCC" here in the GNU GCC FAQ.
There's also a white paper here.
for Ubuntu it's pretty easy
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
and then install for example gcc version 6
sudo apt-get install gcc-6
Have you tried gcc-select? Otherwise, try setting the INCLUDE_PATH and LIBRARY_PATH in your shell.
update-alternatives is a very good way to have multiple gcc versions:
http://ubuntuguide.net/how-to-install-and-setup-gcc-4-1g4-1-in-ubuntu-10-0410-10
You possibly still execute the old gcc. Try making a symlink from gcc to your version of it, like
ln -s gcc-4.1 gcc
Beware of not removing an old "gcc" binary placed there, in case they placed not just a symlink. If you can recompile your own gcc version, the safest is just use another prefix at configure time of gcc, something like --prefix=/home/jojo/usr/gcc (i did it that way with gcc-4.4 from svn-trunk, and it worked great).
Note that that just runs the right gcc version. If you update your gcc, your glibc won't be updated automatically too. It's a separate package which is deeply coupled with the rest of the system. Be careful when installing another glibc version.