XCode: Where is GCC installed? - macos

I've installed XCode v3.1.3 and am having difficulties using the rumored GCC that is installed along with it. -- I'm certainly able to use the XCode IDE to compile my programs but would like the flexibility of also using the command line...
Where's GCC?

Look in /Developer/usr/bin

The most likely explanation is that when you installed the Developer tools you unchecked "UNIX Development Support", so the command line tools were never installed. Delete your /Developer/ directory and do a clean install of the tools; make sure to select "configure" during the installation process and ensure that the appropriate items are checked.

In /usr/bin you should find gcc-4.0 and gcc-4.2 and then there will be a symbolic link gcc which points to one of these (usually gcc-4.2).
As always, you can find out where any available command in your PATH is located using which, e.g.
$ which gcc

Related

Fortran codes won't compile on Mac with gfortran

I recently moved from the SGI, Sun workstation environment to a Mac. SGI and Sun came with Fortran compilers so I have maybe 100 small f77 codes I wrote over the years for post-processing and analysis of simulated data. I was hoping to get these codes running on my iMac with gfortran. Most of these are very simple codes but I can't get them to compile and execute. I tried starting with the basics and wrote the Hello World code from a gfortran help page. My code, fortran.f is:
program helloworld
print *, "hello world"
end program helloworld
When I tried compiling this according to the example I typed:
gfortran fortran.f
But I keep getting the error message:
FATAL:/opt/local/bin/../libexec/as/x86_64/as: I don't understand 'm' flag!
This is the same error message I get on my other codes. Can someone tell me what I'm doing wrong? I can't think of a simpler example but I can't seem to get it to work.
When it comes to macOS, I think that building form sources is the best approach you can have. You can achieve that quite easily by downloading and compiling GFortran as part of GCC directly from: https://gcc.gnu.org/wiki/GFortran
However, there are few things you have to take care of:
make sure you have XCode installed, you can get it here
XCode
XCode is free of charge
Make sure you have command line tools
You can get them either from developer.apple.com
Command Line Tools
or directly from XCode. It might be that XCode will tell you to install Command Line Tools upon first execution
In the past, running command like "svn", when Command Line Tools were not installed, also triggered the installation.
Compile GCC
> ./configure --prefix=$HOME/opt/usr/local
> make all
> make install
Alternatively, you can install using macOS package from GFortran
gfortran-6.3-Sierra.dmg
Fully working sample with Fortran based MPI code:
http://www.owsiak.org/running-open-mpi-on-macos/
If your gfortran was installed a long time ago and you have updated macOS since installing, it may need re-installing to get correctly aligned and linked with the latest macOS tools and libraries.
My advice would be to:
uninstall gfortran,
check that Xcode and its command line tools are up-to-date,
re-install gfortran.
Hints for each of those steps follow:
Note that gfortran is a part of GCC - the "GNU Compiler Collection".
If you installed gfortran via homebrew, you can remove it with:
brew rm gcc
You can update Xcode by by going to AppStore and clicking Updates at top-right.
The Xcode Command Line tools include make and git and command-line versions of the compilers. You can install/update the Xcode command line tools with:
xcode-select --install
You can install gfortran with homebrew using:
brew install gcc
When you are finished, you should make sure that your PATH includes /usr/local/bin near the start and that there are no errors when you run:
brew doctor
which is a brilliant utility that checks your homebrew configuration is correct.
All I had to do was change the path.
Initially, my PATH was something like
/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin
Because of this reason, the default assembler (as) was not called which is in the /usr/bin directory.
To enable the call to the right assembler (as), I had to add /usr/bin to the PATH in front of (before) /opt/local/bin, i.e. on a Mac this can be added by editing ~/.bash_profile such that one's $PATH looks like
/usr/bin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin
Once edited, execute at your command prompt:
source /etc/bash_profile
This worked for me.

Differences between Apple LLVM and LLVM

I have Apple's command line tools version 9.1 installed and am working through an LLVM tutorial. I need to use some libraries like llvm/ADT and llvm/IR but get an error when I run the code.
main.cpp:1:10: fatal error: 'llvm/ADT/APFloat.h' file not found
#include "llvm/ADT/APFloat.h"
^~~~~~~~~~~~~~~~~~~~
1 error generated.
I also don't seem to have tools such as the assembler. Are these things not usable with Apple's version? And can I install LLVM without conflicting with Apple's version?
Apple's fork misses most of the library,headers and command-line tools in the llvm trunk.
I suggest you compile a new llvm copy from trunk.
Conflicting depends on how you configure everything. You can:
Install your new copy to global location, where your $PATH configuration is responsible for choosing which version to use.
Install as a separate Xcode Toolchain.
Here is a build script I've been using:
cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release -DLLVM_APPEND_VC_REV=on -DLLVM_ENABLE_EH=on -DLLVM_ENABLE_RTTI=on -DLLVM_CREATE_XCODE_TOOLCHAIN=on -DCMAKE_INSTALL_PREFIX=~/Library/Developer/ ../LLVM
Running ninja install will install to global location, otherwise run ninja install-xcode-toolchain to install as a separate toolchain
In your case I suggest installing to global location to avoid the trouble of messing with CFLAGS/LDFLAGS/Header Search Path. Then remove the installation manually after you are done with the tutorial
EDIT: You might also want to check out the official build guide https://llvm.org/docs/CMake.html
For your use case, in-tree building is also a feasible option(Providing you are familiar with write cmake configs)
Actually, there is no need to build the LLVM yourself. You can get prebuilt version for your platform here: http://releases.llvm.org
In your case it would be something like this:
cd /opt
wget http://releases.llvm.org/5.0.0/clang+llvm-5.0.0-x86_64-apple-darwin.tar.xz
tar xvf clang+llvm-5.0.0-x86_64-apple-darwin.tar.xz
mv clang+llvm-5.0.0-x86_64-apple-darwin llvm-5.0.0
After that you will have everything under /opt/llvm-5.0.0, e.g.:
/opt/llvm-5.0.0/bin/clang
/opt/llvm-5.0.0/bin/llvm-config
/opt/llvm-5.0.0/lib/libc++.a
etc.
P.S. I use /opt just as an example, feel free to pick any other directory that fits you best.

CLion Installation: Cmake compilers not found, GDB not found

I'm switching from VS to CLion and they said I needed to install Cygwin and CMake. I then installed both of them. I tried use bundled, but CLion still gives me these errors make: not found C Compiler: not found C++ Compiler: not found GDB: not found.
I have installed CMake under the path C:\Users\Gaga\Downloads\cmake-3.4.1 but I don't see a cmake.exe, the closest thing is cmake.cxx.
Without these I'm not able to compile anything, please help
In the "Use specified" field I put C:\cygwin64\bin\cmake.exe your path may be different. Just ensure you have CMake, Make, gdb and gcc installed already in Cygwin (using the Cygwin setup.exe not via the CMake website) but I believe Clion checks if you have them installed after inputting the path.
The workaround would be to use MinGW. If you download it from the website it should come with cmake, and take care of the errors.
http://mingw.org/
When extract it and go to the installer you should check something like gcc and then from the top left corner something like 'install packages'
Be sure not to accidentally download the source, which I did, which would lead you toward this error: CLion: CMake Errors Source directory does not exist
Edit: So over a year later, I've learned a little more about Cygwin and mingw beyond what the internet says. CLion needs a "Unix-like" environment. If you use CLion on MacOS or a Linux it's already Unix based. Anything that is "POSIX" compliant will work. CygWin is a terminal emulator for windows where Unix commands like mkdir work. MinGW is something similar but not posix. Comes with GCC tho. I'm still a noob.
I had the same problem.
While installing cygwin, need to select the packages of cmake, gcc, gdb
Got the answer from the below link.
Select Packages while installing cygwin
After the installation go to the configuration page and select the cygwin directory. CLion will identify the configuration and you are done...

how to install gcc on mac using command line?

I need to install the gcc suite on an OS/X box using the command line. As far as I can tell, the only way to do this is to install Xcode, which appears to only have a GUI install. Surely, this can be done.
You can install any package using command line with installer - the GUI is merely a convenience, you don't need to use it. For example
sudo install -pkg Xcode.mpkg -target /
You can also pick individual packages from the Xcode installation if you wish, for example Packages/llvm-gcc4.2.pkg contains just the compiler.
I believe you are looking for this:
http://solarianprogrammer.com/2011/09/20/compiling-gcc-4-6-1-on-mac-osx-lion/
Mind you this is compiling the latest from source.
You can download pre-built binaries from: https://github.com/kennethreitz/osx-gcc-installer

Where is gcc on OSX? I have installed Xcode already

I have installed Xcode from the Tool cd, I thought that would let me use gcc from the command line but I can't find it.
What am I missing
EDIT
When I wrote I can't find it I meant "I look for it using which gcc"
If gcc would have been in the PATH in first place, which would have find it.
Since gcc is not in the PATH ( that's what brought me here in first place ) which won't find it!
I think that was obvious but I'm making the note here because it wasn't
As of version 4.3.1, XCode is now an application and the command line tools are now available through the Preferences (this is documented in the App Store for XCode under 'What's New in Version 4.3.1' if you click 'More...'). After installing XCode, open it, open the Preferences and click on the Download tab. Click on 'install' for the 'Command Line Tools' and then sign in with your computer's password. The code will then be downloaded and installed.
You didn't check the box that says "UNIX Development Support"[1] (or possibly you unchecked it; I can't remember if it's on by default or not) when you did the install, so it didn't install the necessary symlinks and drivers in /usr/bin/.
Reinstall, and make sure to read the descriptions of the configuration options and select the ones that you need.
1: "Optional content to allow command-line development from the boot volume. Installs a duplicate of the GCC compiler and command line tools blah blah blah..."
Something went wrong with your install.
gcc is installed under /usr/bin with a symlink to gcc-4.2:
cd diciu$ pkgutil --file-info /usr/bin/gcc-4.2
volume: /
path: /usr/bin/gcc-4.2
pkgid: com.apple.pkg.gcc4.2Leo
pkg-version: 4.2.0.9000000000.1.1249367152
[..]
pkgid: com.apple.pkg.Xcode3.2.1Update
pkg-version: 1.0.1.1249367152
[..]
pkgid: com.apple.pkg.Xcode3.2.1UpdateUNIXDevSupport
pkg-version: 1.0.1.1249367152
[..]
On my Mac $ which gcc displays /usr/bin/gcc.
Xcode 4.3+ you need to install 'Command Line Tools for Xcode' found here: https://developer.apple.com/downloads
Is it possible that rather than not having gcc installed, your $PATH variable is messed up? first check if gcc is in /usr/bin manually. Then echo $PATH...
The same thing happened to me. It worked for a while and then went away. Reinstall and it will be fixed.
You might want to download Xcode from Apple while you are at it. Almost guaranteed to be fresher / more up-to-date since Xcode is rapidly updated. Current Xcode is 3.2.1.10. You need an Apple ID to download, but that also gives you access to the development site. All free... .
It is 1/6/2014. Current Xcode is 5.0.1
It is 2016 -- Current Xcode is 8.0. I think this question should be closed now.
Yes, try to install 'command line tools' by clicking Preferences-Downloads-command line tools.

Resources