Mac os x compilers

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.

Источник

C, C#,C++ Compilers for Mac OS X

Cross Compilers for Mac OS X

For some of my softwares, I needed to built a multi platform distribution package, including executable for Windows and Linux. As I mainly work on Mac, I have decided to built GCC cross compilers for Windows and Linux. Then I have built Mac OS X packages in order to make installation simplest.

Compiling for WIN32 on Mac OS X

This is a cross compilation of MinGW on Mac OS X.

A package installs all files in the given intallation directory, for example in /usr/local/i386-mingw32-3.4.5 for release 2 for Intel Mac.

All tools are located in the bin sub directory. You can add this path to your $PATH shell variable, or invoke the tools with their full path name: for example /usr/local/i386-mingw32-3.4.5/bin/i386-mingw32-gcc for gcc. Note tool names always begin by i386 , even for Power PC: for example, /usr/local/ppc-mingw32-4.3.0/bin/i386-mingw32-gcc .

You can find some sample code in MinGW sample code page.

MinGW Binaries for Intel

Version
Corresponds to…
Implemented languages
Installer to download
Installation directory

3 (february 2009)
MinGW 4.3.0
C, C++, Objective-C, Objective C++, Java, Fortran
MinGW 4.3.0 for Mac OS X (Intel).pkg.tar.bz2 (40.7 MB)
/usr/local/i386-mingw32-4.3.0/

2 (december 2006)
MinGW 3.4.5
C, C++, Objective-C, Java, Ada, Fortran 77
MinGW-3.4.5-for-Mac-OS-X-Intel.tar.bz2 (38.4 MB)
/usr/local/i386-mingw32-3.4.5/

MinGW Binaries for ppc

Binaries for pcc should work on Mac OS X.3 and later.

Version
Corresponds to…
Implemented languages
Installer to download
Intallation directory

3 (february 2009)
MinGW 4.3.0
C, C++, Objective-C, Objective C++, Java, Fortran
MinGW 4.3.0 for Mac OS X (PPC).pkg.tar.bz2 (38.3 MB)
/usr/local/ppc-mingw32-4.3.0/

2 (december 2006)
MinGW 3.4.5
C, C++, Objective-C, Java, Ada, Fortran 77
MinGW-3.4.5-for-Mac-OS-X-ppc.tar.bz2 (38.3 MB)
/usr/local/i386-mingw32-3.4.5/

1 (december 2005)
MinGW 3.4.4
C, C++, Objective-C, Java, Ada, Fortran 77
MinGW-3.4.4-for-Mac-OS-X-ppc.tar.bz2 (37 MB)
/usr/local/i386-mingw32-3.4.4/

Yes, it is an error, ppc binaries for versions 1 and 2 install in an i386… directory.

Compiling for Linux on MacOS X

This is a cross compilation of GCC on Mac OS X.

A package installs all files in the given installation directory. Within the installed directory, the contents.txt file contains the detail of cross-compiled archives.

All tools are located in the bin sub directory. You can add this path to your PATH shell variable, or invoke the tools with their full path name: for example /usr/local/gcc-4.5.2-for-linux32/bin/i586-pc-linux-gcc for gcc.

For better portability of Linux tools built with theses cross compilation chains, invoke the linker with the -static option, for example:

/usr/local/gcc-4.5.2-for-linux32/bin/i586-pc-linux-gcc -static for C linking;

/usr/local/gcc-4.5.2-for-linux32/bin/i586-pc-linux-g++ -static for C++ linking.

32-Bit Linux Binaries for Mac Intel

Version
Corresponds to…
Implemented languages
Installer to download
Installation directory

64-Bit Linux Binaries for Mac Intel

Version
Corresponds to…
Implemented languages
Installer to download
Installation directory

Compiling for Renesas H8 on MacOS X

KPIT Cummins provides KPIT GNU Tools for Renesas micros. Here is a cross compilation of GNU H8 compiler suite for Mac OS X, from sources provided by KPIT Cummins.

You can find here Intel binaries, Power PC binaries, and source packages.

Compiling for ARM on MacOS X

You can find here Intel binaries, Power PC binaries, and source packages for compiling for ARM on Mac OS X.

License

Copyright © 2005, 2006, 2009, 2010 by Pierre Molinaro

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Источник

5 Ways to Write C++ Code on Your Mac

This article is intended primarily for students leaning C++ for the first time on a Mac. It’s not a step-by-step tutorial on how to write and compile code in the applications described. That will require digging in and mastering the mechanics of each method described. Rather, it’s a quick start guide that points to the basics and provides simple examples of how C++ coding can be accomplished on a Mac.

Yes, there are lots of ways to write C++ on a Mac

Scope of Article

All of the solutions provided can be used in the writing of the kinds of code beginners write: 20 to 50 lines of code that assist with the learning of C++. Stdin and stdout are the focus. Others can do much more. The writing of a full-featured GUI app for macOS is not covered.

The article could also be used by professionals who’ve already been doing professional C++ on, say, a corporate Linux system. However, it may not be clear how to get started and which tools to use in a transition to a Mac.

This article provides an overview of five good ways to write C++ on a Mac. There may be more. Most discussed are free, but one incurs a modest cost. Some are full featured, and some have limitations. For example some solutions presented don’t lend themselves to debugging thanks to decisions Apple has made. For all these reasons, it’s hard to rank the various solutions by some standard. After you’ve read about them, it may well be that one is the obvious way to proceed initially. See the spreadsheet on page 6.

First, a bit of nomenclature. We’ll talk here about an Integrated Development Environment (IDE). From Techtarget:

An integrated development environment (IDE) is a software suite that consolidates the basic tools developers need to write and test software. Typically, an IDE contains a code editor, a compiler or interpreter and a debugger that the developer accesses through a single graphical user interface (GUI).

What follows is a thumbnail sketch of each approach. As always, it’s up to the student to install and learn the nuances of each one. We’ll provide merely a grand tour and some overall guidance.

Finally, in the screen shots below, for clarity, the important area only is shown. That’s because showing the entire window often makes the key region too small to read.

1. Apple’s Xcode IDE

As mentioned above, Apple’s Xcode is a free, full featured IDE for native apps. However, it’s not very hard to press it into service for beginning C++ code on a Mac, and it includes a GUI debugger.

Note that Xcode is designed specifically for developers to write macOS, iOS, tvOS and watchOS applications in Swift or Objective-C. Because of that, it’s not widely used in industry or education as a C++ development system. In those situations, the focus is on Linux and Java-based IDEs. But Xcode is free, powerful and turns out to be amazingly useful for the student with a Mac.

All you need is a (free) AppleID and then you can download it from the Mac App Store found in macOS: Apple Menu > App Store. The latest version as of this writing is 8.3.3 and is designed to work with macOS Sierra.

Xcode in Mac App Store

1.1 After you install Xcode, there will be an app in /Applications called Xcode.app. When you lunch it, you’ll see:

1.2. Select “Create a new Xcode Project.” Then click on “Command Line Tool.”

Select the “Command Line Tool.”

1.3. Fill in the various fields, as you wish, and select C++ from the Language popup.

1.4. At this point, you’ll need to learn about how to enter code into the editor, build (compile and link), display the stdin/stdout and debug windows, and run the app. Here’s how it looks with some sample C++ code designed to calculate the area of a rectangle..

C++ in Xcode with input and output (bottom right).

A final note. You’ll be able to create breakpoints and display variables in Xcode like this:

Xcode debug with breakpoint and variables shown.

For the beginning C++ student who is familiar with the Mac, this is a great way to go. But there are more options, so off we go.

Next: Method #2 – Install Linux as a Virtual Machine in macOS.

Источник

Читайте также:  Какая версия windows самая быстрая
Оцените статью