- Mac OS X: Install GCC Compiler with Xcode
- Step #1: Install Xcode on a Apple Mac OS X
- Step #2: Install gcc/LLVM compiler on OS X
- Step #3: Verification
- Testing sample “Hello world” C program
- How to install gcc compiler on Mac OS X
- Solution
- 1. Register Apple Developer Account
- 2. Command Line Tools for Xcode
- 3. Installation
- 4. Verification
- GCC for Mac
- Review
- Free Download
- specifications
- A comprehensive and useful compiler system that comes with in-built front-ends and libraries designed to support a wide variety of programming languages
- What’s new in GCC 11.2.0:
- Take advantage of the support for numerous programing languages
- Compatible with various processor architectures
- Expandable through plugins
- Solarian Programmer
- My programming ramblings
- Compiling GCC 10 on macOS Catalina
- Posted on October 12, 2019 by Paul
Mac OS X: Install GCC Compiler with Xcode
I have Mac OS X Mountain Lion. I need to compile a few apps and Perl modules. I already installed Xcode from app store but I’m unable to find gcc compiler or make command. How do I install gcc on Mac OS X 10.8.x?
Tutorial details | |
---|---|
Difficulty level | Easy |
Root privileges | Yes |
Requirements | Mac OS X Mountain Lion |
Est. reading time | Depends on the internet speed |
Xcode includes command line development tools such as gcc and friends.
Step #1: Install Xcode on a Apple Mac OS X
First, make sure Xcode is installed. If it is not installed on OS X, visit app store and install Xcode.
Fig.01: Make sure Xcode developer tools are install OS X
Step #2: Install gcc/LLVM compiler on OS X
Once installed, open Xcode and visit:
Xcode menu > Preferences > Downloads > choose » Command line tools » > Click » Install » button:
Fig.02: Installing gcc compiler on Mac OS X
Step #3: Verification
Open a terminal app and type the following commands:
$ gcc —version
$ whereis gcc
$ whereis make
Sample outputs:
Fig.03: Verify gcc compiler installation on Mountain Lion OS X
- No ads and tracking
- In-depth guides for developers and sysadmins at Opensourceflare✨
- Join my Patreon to support independent content creators and start reading latest guides:
- How to set up Redis sentinel cluster on Ubuntu or Debian Linux
- How To Set Up SSH Keys With YubiKey as two-factor authentication (U2F/FIDO2)
- How to set up Mariadb Galera cluster on Ubuntu or Debian Linux
- A podman tutorial for beginners – part I (run Linux containers without Docker and in daemonless mode)
- How to protect Linux against rogue USB devices using USBGuard
Join Patreon ➔
Testing sample “Hello world” C program
Create a text file called a.c as follows using a text editor such as vi or cat command:
To compile, enter:
$ make a
Run it as follows:
$ ./a
Sample outputs:
Fig.04: Compiling and running sample “Hello world” C program on Mountain Lion 10.8.4
See also
And, there you have it, the gcc version 4.2.1 installed and working correctly on the latest version of Mac OS X 10.8.4. In Apple’s version of GCC, both cc and gcc are actually symbolic links to the llvm-gcc compiler. Similarly, c++ and g++ are links to llvm-g++. For more information and examples see the following man pages:
$ man gcc $ man make
🐧 Get the latest tutorials on Linux, Open Source & DevOps via
Category | List of Unix and Linux commands |
---|---|
Documentation | help • mandb • man • pinfo |
Disk space analyzers | df • duf • ncdu • pydf |
File Management | cat • cp • less • mkdir • more • tree |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Linux Desktop Apps | Skype • Spotify • VLC 3 |
Modern utilities | bat • exa |
Network Utilities | NetHogs • dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtop |
Searching | ag • grep • whereis • which |
Shell builtins | compgen • echo • printf |
Text processing | cut • rev |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
Comments on this entry are closed.
There is no need to install huge xcode consumes gigabytes of disk space (if you are not a apple developer), just go to the apple’s developer page and download the “command line tool for xcode” package and install it, that would be just sufficient.
Isn’t GCC is LLVM with GCC support and many automake, m4 etc… project is not enable to build.
thank u very very very much you are really clever
THANK YOU SO MUCH. Everything else I tried didn’t seem to work. Finally this did.
Thank you very much. It worked.
I installed the Xcode Command Line Tools, and when I try to find gcc in the terminal
tell me this:
asaffeldman$ $gcc –version
-bash: –version: command not found
with 2 dashes and no $ in front of it
hope it helps!
Clear , efficient , thanks !
I have GCC 4.8.1 with x86, x86_64 and PPC on Lion with ObjC, C/C++11, Fortan, Ada Go support.
And now I can compile PHP, WxWidgets, QT and many other source without problems like on Apple Clang vesion. In xcode too.
Gcc builded with llvm-gcc-4.2.
i m doing the c programming on terminal my keyword is not highlited by compiler,
strstr function is not working why plz resolve my problm
hi
when I typed make a I got this message:
make: *** No rule to make target `a’. Stop.
please help me.
Thanks.
I got the same error when I didn’t spell the filename with the exact case.
Hi , I installed xcode and command line tools just as you said but when I try the command gcc –version I get this error
Error: could not stat active Xcode path ‘/Volumes/Xcode/Xcode.app/Contents/Developer’. (No such file or directory)
Is my xCode in the wrong place? It’s installed and under Applications, please help
I AM GETTING THIS ERROR IN XCODE WHILE I AM BUILDING A PROGRAM IN C++
I don’t have the Command Line option in my preference. Help!
Источник
How to install gcc compiler on Mac OS X
By mkyong | Last updated: August 29, 2012
Viewed: 400,908 (+568 pv/w)
Often times, you need c or gcc compiler to compile open source projects in Mac OS X. The problem is Mac OS X doesn’t install the gcc compiler by default.
If you try to install or compile some projects that required c/gcc compiler, following errors message will be logged :
In terminal, type “ gcc “, you will get message “command not found”.
Solution
To install gcc compiler on Mac OS X, you need to download and install “Command Line Tools for Xcode”, which is available in Apple’s developer page. See following steps :
1. Register Apple Developer Account
Access Apple’s developer page, to process on the download, you need to register an Apple account, it’s free, but need to spend few minutes to fill in the survey.
2. Command Line Tools for Xcode
In Apple developer page, “Developer Tools” category, find “Command Line Tools for Xcode“, choose your version and click on the xx.dmg file (file size is 100mb ++) to start the download.
3. Installation
After .dmg file is downloaded, a small dialog will be prompted and show you this file – “Command Line Tools.mpkg“, just double click on it, follow the wizard guide to complete the installation.
4. Verification
After installation is completed, run “ gcc -v ” in terminal again. If everything fine, following output will be displayed.
Done, the gcc version 4.2.1 is installed on Mac OS X successfully.
Источник
GCC for Mac
Review
Free Download
specifications
A comprehensive and useful compiler system that comes with in-built front-ends and libraries designed to support a wide variety of programming languages
What’s new in GCC 11.2.0:
- Caveats:
- The default mode for C++ is now -std=gnu++17 instead of -std=gnu++14. Note that C++17 changes to template template parameter matching can be disabled independently of other features with -fno-new-ttp-matching.
- When building GCC itself, the host compiler must now support C++11, rather than C++98. In particular bootstrapping GCC 11 using an older version of GCC requires a binary of GCC 4.8 or later, rather than of GCC 3.4 or later as was the case for bootstrapping GCC 10.
Read the full changelog
The GNU Compiler Collection or GCC for short, comprises front ends for C, Objective-C, C++, Java, Fortran, Go and Ada, along with libraries for the mentioned languages.
GCC us the main component of the GNU toolchain, it is distributed under the GNU General Public License and plays a central role in the continuous growth of free software.
Take advantage of the support for numerous programing languages
Initially, GCC handled only the C programming language, but with the development of additional front ends, GCC expanded to compile C++, Objective-C, Objective-C++, Go, Fortran, Ada, Java and others.
GCC also offers support for a wide variety of processor architectures and, as a result, it is frequently used as a development tool for both free and proprietary apps. GCC is also available for most embedded platforms, including AMCC, Symbian and Freescale Power Architecture-based chips.
Compatible with various processor architectures
The GNU Compiler Collection also targets various platforms, such as video game consoles like Dreamcast and PlayStation. Moreover, GCC is the standard compile for numerous Unix-like operating systems, including Linux and the BSD family, FreeBSD and LLVM system.
Thanks to GCC’s Link-time optimization feature it optimizes across object file boundaries in order to improve the linked binary. Link-time is based on intermediate files containing the serialization of various Gimple representation present in the object file.
Expandable through plugins
Moreover, the use of plugins enables you to extend the GCC compiler and modify stock compilers to fit specific needs by loading external codes as plugins. As follows, you can use plugins to add, remove and replace middle-end passes operating on Gimple representations.
Detailed installation instructions along with the provided documentation are available on GCC’s Installation webpage.
In conclusion, GCC is a comprehensive collection of libraries and front ends that enable you to compile source code into binary application.
Источник
Solarian Programmer
My programming ramblings
Compiling GCC 10 on macOS Catalina
Posted on October 12, 2019 by Paul
Updated 8 May 2020
In this tutorial, I will show you how to compile from source and install the current stable version of GCC on your macOS computer. The instructions from this tutorial were tested on Catalina (macOS 10.15).
Clang, the default compiler for macOS, supports only C, C++, Objective-C and Objective-C++. If you are interested in a modern Fortran compiler, e.g. you will need gfortran that comes with GCC. Another reason to have the latest stable version of GCC on your macOS is that it provides you with an alternative C and C++ compiler. Testing your code with two different compilers is always a good idea.
Building GCC 10 from sources could take some time, in my case it took about two hours on a MacBook Air with a 16GB of RAM.
In order to compile GCC from sources you will need a working C++ compiler. In the remaining of this article I will assume that you have installed the Command Line Tools for Xcode. At the time of this writing Apple’s Command Line Tools maps the gcc and g++ to clang and clang++. If you don’t have the Command Line Tools installed, open a Terminal and write:
which will guide you through the installation process.
Let’s start by creating a working folder:
Next, we can download and extract the latest stable version of GCC:
GCC 10 depends on a couple of other libraries (GSL, GMP, MPFR and ISL) that can be downloaded with:
the above four prerequisites will be built during the GCC build.
We are ready to compile GCC now. Be prepared that this could take some time … Since I’m interested only in the C, C++ and Fortran compilers, this is the configure command I’ve used on my machine:
The above command instructs the configure app to add a prefix to all the resulting executable programs, so for example if you want to invoke GCC 10.1.0 you will write gcc-10.1, the gcc command will invoke Apple’s version of clang.
If you are interested in building more compilers available in the GCC collection modify the –enable-languages configure option.
And now, the final touches:
Grab a coffee, maybe a book, and wait … this should take approximately, depending on your computer configuration, an hour … or more … and about 4.15GB of your disk space for the build folder.
Install the compiled gcc in /usr/local/gcc-10.1.0:
Now, you can keep the new compiler completely isolated from your Apple’s gcc compiler and, when you need to use it, just modify your path by writing in Terminal:
If you want to avoid writing the above command each time you open a Terminal, save the above command in the file .zshrc from your Home folder, e.g:
You should be able to invoke any of the newly built compilers C, C++, Fortran …, invoking g++ is as simple as writing in your Terminal:
Remember to erase the working folder from your HOME if you want to recover some space:
Next, I’ll show you how to check if the compiler was properly installed by compiling and running a few examples. GCC 10 uses by default the C++14 standard and C11 for the C coders, you should be able to compile any valid C++14 code directly. In your favorite text editor, copy and save this test program (I’ll assume you will save the file in your Home directory):
Compiling and running the above lambda example:
We could also compile a C++ code that uses threads:
Next, we present a simple C++ code that uses regular expressions to check if the input read from stdin is a floating point number:
If you are a Fortran programmer, you can use some of the Fortran 2008 features like do concurrent with gfortran-10.1:
The above code can be compiled with (assuming you’ve saved it as tst_concurrent_do.f90):
If you are interested in learning more about the new C++11/C++14 syntax I would recommend reading The C++ Programming Language by Bjarne Stroustrup.
or, Professional C++ by M. Gregoire, N. A. Solter, S. J. Kleper 2nd edition:
If you need to brush your Fortran knowledge a good book is Modern Fortran Explained by M. Metcalf, J. Reid and M. Cohen:
Источник