Installing gcc on mac os

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 на Mac OS X 10.8 / Xcode 4.4

Я установил Mountain Lion (Mac OS X 10.8), и теперь gcc, похоже, больше не доступен. Я также установил Xcode 4.4, поэтому больше нет каталога / Developer.

Мне нужен gcc как для портов mac, так и для ruby gems (которые имеют собственные расширения).

включает ли Xcode 4.4 gcc или есть способ установить gcc?

9 ответов

обновление:

теперь вы можете просто выполнить следующую команду из вашего терминала:

начиная с Xcode 4.3-теперь вы должны вручную установить инструменты командной строки из Xcode menu > Preferences > Downloads .

кроме того, существуют автономные пакеты установки как для Mountain Lion (10.8) и для Mavericks (10.9).

этот пакет включает UNIX-стиль разработка через терминал путем установки инструменты разработчика командной строки, а также фреймворки Mac OS X SDK и заголовки. многие полезные инструменты включены, такие как Apple LLVM компилятор, компоновщик и сделать. если вы используете Xcode, эти инструменты также встроенный в Xcode IDE и может быть установлен в вашей системе использование панели настроек загрузки в Xcode 4.3 и более поздних версиях. Этот пакет требует Mac OS X 10.7.3 или более поздней версии.

я обнаружил, что после обновления с Lion моя установка не удалась, потому что она искала GCC в /usr/bin/gcc-4.2. Теперь путь установки по умолчанию — /usr/bin / gcc.

моя ошибка выглядела так:

символическая ссылка разберется с проблемой:

Источник

jagger27 / gcc-on-osx.md

Compiling and Running C on Mac OS X Yosemite

If you’re like me, you find working on the provided Ubuntu VM to be tortuous and inefficient. It’s such a shame to be running an operating system with all of the tools to you need to compile and run simple toy C programs but being forced to use a clunky virtual machine without all your favourite software. Here’s what I do to ease the pain.

This guide was tested on Mac OS X 10.10 Yosemite, but should also work on any version of OS X that Homebrew supports. It should work just fine on Mavericks, plus you get access to valgrind. (valgrind hasn’t been ported to 10.10 yet, but it does work on 10.9)

By default, if you have Xcode installed, typing gcc into Terminal.app links to the llvm/clang compiler. Although clang is a great, modern compiler it isn’t what’s specified by the professor and could potentially lead to incompatible code (and lost marks). To avoid this, we can install and run the same (*a slightly newer) version of gcc natively on our Macs.

If you don’t already have Homebrew installed, go ahead and do that now. For those of you familiar with Linux package managers, Homebrew is essentially Aptitude (apt-get) for OS X.

The installer will guide you through installing any missing dependencies you may have. (Commonly Xcode tools)

Once Homebrew is installed, brew install gcc

And that’s pretty much it. But you have to watch out; gcc is actually just clang plus some extra libraries, you need to run gcc-4.9 instead.

Notice how gcc -v spits out something like

Which, clearly, isn’t what we want. Notice the slight difference between clang -v and gcc -v .

Whereas gcc-4.9 -v should show something like

Note: if gcc-4.9 isn’t being found, try opening a new shell. The $PATH sources need to be refreshed.

It’s probably a bad idea to alias gcc to gcc-4.9 because some programs (Homebrew included) may expect clang. Instead, I suggest using Makefiles to easily specify your compiler.

ALWAYS test your code in the provided VM before submitting! You have been warned.

Another option is just to use what’s included with your system. llvm/clang is a very capable, modern compiler and can, for the most part, compile the exact same code that works in gcc, at least in the scope of COMP 2401.

gcc (clang) appears to compile everything as C++ code, so you’ll probably get some weird warnings that you otherwise wouldn’t have seen. Fortunately, I’ve found that fixing things for clang tends to keep gcc-4.9 happy.

Источник

Install GCC Without XCode in Mac OS X

If you compile your own software you probably know that GCC comes bundled in the rather large Xcode package, but what if you just want to have gcc and LLVM without installing the entire Xcode package? Apple now offers an option to do just that, and it’s called Command Line Tools, available as a separate download from Apple Developers.

You’ll need a free developer login to access the download, login and look for “Command Line Tools for Xcode”. Mac OS X 10.7.3 or later is required to use the package installer.

The download is less than 150MB and that alone will save plenty of bandwidth, but the total installation is also significantly smaller than Xcodes footprint and you’ll save a ton of disk space if you just want the command line compiler tools without all the iOS and OS X development support.

If you already have Xcode installed you won’t need this because it’s an option during the general Xcode installation, meaning this is really just for advanced Mac users that want the familiar unix compiler toolkit; Make, GCC, LLVM, python, perl, and other development utilities. If you want to slim down your development footprint, you can always uninstall Xcode by deleting the app from /Applications/ and then manually install the Command Line Tools for OS X separately.

Источник

Читайте также:  Видеоредактор для слабых пк linux
Оцените статью