- 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
- GNU compiler install on Mac OS X
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.
Источник
GNU compiler install on Mac OS X
After installing the GNU compilers, you may want to check out the HOWTO for installing Open MPI on Mac OS X.
Background
One of the nice things about Mac OS X is that you have a polished user interface atop a Unix operating system. This means that using command line utilities such as compilers is straightforward, making coding on your Mac easy. If you have a multi-core Mac (most should by now) and would like to run codes that use MPI to distribute processing across multiple processor cores, you should also check out the HOWTO for installing Open MPI on Mac OS X. Note that you’ll need to follow the instructions on this page prior to installing Open MPI if you don’t already have some set of compilers installed.
Requirements
To install the GNU compilers as described in this HOWTO, you’ll need the following:
- A Mac running 10.11 (El Capitan)
- If you are using Mac OS X 10.6 — 10.10, check out the instructions for older versions of Mac OS X
- An Apple App Store account
- Internet access
Video instructions for Mac OS 10.11 (El Capitan) with Xcode 7
Rough video transcript:
Hello, and welcome to this screencast on how to install the GNU C, C++ and Fortran compilers for Mac OS 10.11 (El Capitan). In this video, I will show you how to install the compilers as well as Apple’s Xcode software, which is required for the compiler installation. For this video, I am assuming you are using a Mac running Mac OS 10.11, also known as El Capitan, that you have an Apple App Store account and that you have internet access. I am also assuming you have administrator access on your Mac, allowing you to install software. If you’re running an older version of Mac OS X, the installation procedure will be similar, but you can check out the link at the end of this video for the installation procedure on older versions of Mac OS X back to 10.6.
Step 1: We’ll begin by installing the current version of Apple’s Xcode software, Xcode 7. To install Xcode, start by opening the App Store app by clicking on the Apple logo on the top left of the menu bar and then selecting App Store… Once the App Store app opens, enter «Xcode» into the search and press Enter. You can now click install to install Xcode. You may be prompted to enter your Apple ID and password if you’ve not previously installed applications via the App Store. Xcode is a pretty big download, so depending on the speed of your internet connection it may take some time to download and install. I’ll be back once the install is complete.
Step 2: Xcode has been downloaded and installed, and now we can move on to a critical second step for the Xcode install, installing the command line tools. To do this, we can use Spotlight to open the Terminal app. If you’re installing compilers, I am going to assume you’re at least somewhat familiar with using a terminal emulator. If not, you should still be able to do the install by following these instructions carefully. Once Terminal has opened, type in xcode-select —install . This will install the command line tools for Xcode, and you will be asked to perform the install using the typical application installation process. This may include asking you for your password.
Step 3: Now that Xcode is fully installed, we can move on to downloading the GNU compilers from the High-Performance Computing for Mac OS X website. The easiest way to get there is to open a web browser, Safari in this case. And type in «High-performance computing Mac OS X» in the Google search. It should be the top hit. On that page, we’ll grab the latest STABLE version of the GCC compiler package and click the link to download.
Step 4: After the compilers have downloaded, we can return to the Terminal and navigate to the Downloads directory. We’ll install the compilers now using the ` sudo ` command, and before we do so, I’m going to give you a little warning. Using the sudo command can do major damage to your computer if you aren’t careful , so please type the following exactly as shown to do the install: sudo tar -xvf gcc-5.3-bin.tar -C / . If your downloaded package ends in .tar.gz , you’ll need to add z to the list of flags after the tar command. This should take just a moment and will install the compilers in /usr/local .
Step 5: Now the compilers are installed, and if you’re running Mac OS 10.11, you should be able to test the installation by typing gcc -v . It should show version 5.3. You can try the same with the Fortran compiler by typing gfortran -v . If they return the compiler versions as expected, you’re all set. Enjoy.
— If your compilers are not installed, you may need to add the installation location to the PATH environment variable, which tells the computer where to look for command line programs.
— In that case, the easiest thing to do is go to the installation HOWTO at the link at the end of this video and check out the last section of the instructions for the installation for Mac OS 10.9 or 10.10. There are some additional instructions that may help resolve your issues. If you’re still having trouble, double check you’ve followed the instructions exactly as given in the video and feel free to add a comment if you still need some help.
— OK, so that’s it. Thank you for watching. If you have any comments, please leave them below. In case you’re interested, here’s another link to a video on how to install the Open MPI software for running multi-core applications on your Mac using MPI, the message-passing interface. Good luck!
Instructions for older versions of Mac OS X (10.6 — 10.10)
Instructions for installing the GNU compilers for older versions of Mac OS X (10.6 — 10.10) have been moved and are available on another page.
Tips & Warnings
I mention all but the last of these tips and warnings in the text above, but it doesn’t hurt to list them a second time.
- Beware that using sudo can do major damage to your computer if you aren’t careful.
- Note that after installing Xcode, you also need to perform a critical additional step.
- Launch Xcode and install any available updates. Quit Xcode.
- Launch Terminal.app (in /Applications/Utilities , hopefully you know that)
Install the Command Line Tools for OS X by typing
This will open a dialog box to install the Command Line Tools for Xcode package. Install following the standard procedure.
Open a new terminal window using your terminal emulator of choice. This will reread the either the .bash_profile file or the .bashrc . If the new gcc version is not returned when typing
then your terminal emulator may be reading the .bashrc file.
Create a symbolic link called .bashrc that points to .bash_profile by typing
Modify the order of directories that are searched for commands by typing
Источник