Can I use gcc 4.7 (and C++11) on Mountain Lion without installing XCode? - c++

I've been using command line tools and a text editor to compile class projects, which has worked great. Unfortunately, they've become sticklers about us using 4.7. Xcode (and thus OSX) only has llvm-gcc 4.2, so I was looking to upgrade.
I've got macports installed and have found instructions for installing gcc 4.7, but it says that I need xcode installed. I was hoping to be able to just use command line tools and not have xcode (I don't need any of the iOS or graphics stuff, I just want gcc.
Anyway, if it's not possible, it's no big deal, but I'd be appreciative if anyone could point me in the right direction. Thanks!
To clarify, I have command line tools, but not the version of gcc I'd like. Running macports results in this:
$ sudo port install gcc47
Error:
Error: No Xcode installation was found.
Error: Please install Xcode and/or run xcode-select to specify its location.
Error:
Error: The installed version of Xcode (2.0orlower) is too old to use on the installed OS version.
Version 4.1 or later is recommended on Mac OS X 10.8.

Related

Run C++ on MacOS without xcode

I don't have Xcode installed on my Mac OS 13.6 but I would like to run c++ on vs code. Is there a way to do that without the need for Xcode to be installed? Also, can I run an older version of Xcode and run c++ without problems?
Note: Would be great if someone posted a link for a tutorial.
You may download and install LLVM 13.0.1 for Darwin or a small part of Xcode, Xcode command line tools: xcode-select --install.
Both will result in installing clang++.

Compiling on Snow Leopard: C and C++ compilers are different

I am trying to compile Icecat on a 32bit iMac with Snow Leopard.
I've installed the latest versions of Xcode, Tigerbrew, Yasm, Python 2.7, Python 3.5, and PIP (and I'm using Autoconf2.13).
I'm able to get up to the configure part, and then when I run this:
../configure --with-l10n-base=../l10n --enable-official-branding
I get the following error:
configure: error: Your C and C++ compilers are different. You need to use the same compiler.
My GCC, G++ versions are both 4.2.1 when I query them with --version
I've scoured the internet for related things but I can't for the life of me figure out how to fix this.
Here is the link I'm following:
https://libreplanet.org/wiki/Group:IceCat/Compile_and_package/build_52.3.0_on_macOS_10.13_High_Sierra
Any help is appreciated.

OpenMP on Mac not working anymore

I had OpenMP compiling and executing in C/C++ on my Mac but then I formatted and reinstalled a fresh copy of OS X. I believe the only difference in the setup was that I had Xcode 5 before the format, and now I have Xcode 6.
Now I get fatal error: 'omp.h' file not found
I read this has something to do with clang and gcc, but, my confusion lies with why did it work before and now its not working?
After some research I seem to have found an answer.
GCC included in the latest version of Xcode (Xcode 6) is only a symbolic link to clang. Since clang does not support OpenMP at this time, you need to install a different version of GCC. The easiest way to do this would be to use Homebrew or MacPorts.
Keep in mind that even when you do this you will probably need to alter your $PATH to have /usr/local come before /usr/bin. This is because Homebrew will have placed your newly installed GCC in /usr/local. Also, some implementations may name the command gcc-49 instead of plain gcc.
Mac OSX uses clang.The gcc compiler in OS X does not support OpenMP. To use this feature a new gcc compiler needs to be installed.
Go to Terminal, if you have not installed Hombrew, install it:
/usr/bin/ruby -e "$(curl -fsSL https://`enter code here`raw.githubusercontent.com/Homebrew/install/master/install)"
then install new version of gcc
brew reinstall gcc --without-multilib
This will not make changes to the existing gcc compiler installed by Xcode as we are reinstalling it.
After running the command given below compile the files using the new version of gcc using the syntax : gcc-version -fopenmp filename.c
To find the version type gcc and then press tab. This will list out all the possible variants of gcc. The version number can be found out from this. For example : gcc-6, gcc-4.9,etc

How to update the clang version to compile a C++11 project? (on Mac)

I'm trying to build a project which is originally written for archlinux. The building process works fine on that archlinux but has a huge amount of errors when I tried to build it on my mac. The project is basically written in C++11 so it's very unstable. I think there has something to do with the compiler because the clang version in mac is 4.2(It actually shows 'Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)' when I type clang --version) and 3.3 for linux. So I want a different version of clang, perhaps 3.3. How Can I specify the version of my compiler when trying to build the project?
Some might argue this belongs on apple.stackexchange.com, but I'm not sure C++11 tags grab a lot of attention there:)
Xcode 5.0 is now available from the App Store. Install it, go to Preferences -> Downloads, and install the Command Line Tools. However...
First, you will need to go to Preferences -> Accounts and add your Apple ID. For some reason, the Command Line Tools download requires an account login. I don't know what the rationale for this is.
> clang -v
Apple LLVM version 5.0 (clang-500.2.75) (based on LLVM 3.3svn)
If you are willing to build from the command line, using make for example (which sounds likely given the project is from Linux), then install Macports and install whatever version of clang you would like:
$sudo port install clang-3.1
$sudo clang_select
Note that this version of clang shouldn't interfere with the Xcode Command Line package if you are will to invoke the Xcode version using xcrun clang instead of plain old clang.

How do I install g++ on MacOS X?

I want to compile C++ code on MacOS X, using the g++ compiler. How do I install it?
That's the compiler that comes with Apple's XCode tools package. They've hacked on it a little, but basically it's just g++.
You can download XCode for free (well, mostly, you do have to sign up to become an ADC member, but that's free too) here: http://developer.apple.com/technology/xcode.html
Edit 2013-01-25: This answer was correct in 2010. It needs an update.
While XCode tools still has a command-line C++ compiler, In recent versions of OS X (I think 10.7 and later) have switched to clang/llvm (mostly because Apple wants all the benefits of Open Source without having to contribute back and clang is BSD licensed). Secondly, I think all you have to do to install XCode is to download it from the App store. I'm pretty sure it's free there.
So, in order to get g++ you'll have to use something like homebrew (seemingly the current way to install Open Source software on the Mac (though homebrew has a lot of caveats surrounding installing gcc using it)), fink (basically Debian's apt system for OS X/Darwin), or MacPorts (Basically, OpenBSDs ports system for OS X/Darwin) to get it.
Fink definitely has the right packages. On 2016-12-26, it had gcc 5 and gcc 6 packages.
I'm less familiar with how MacPorts works, though some initial cursory investigation indicates they have the relevant packages as well.
Installing XCode requires:
Enrolling on the Apple website (not fun)
Downloading a 4.7G installer
To install g++ *WITHOUT* having to download the MASSIVE 4.7G xCode install, try this package:
https://github.com/kennethreitz/osx-gcc-installer
The DMG files linked on that page are ~270M and much quicker to install. This was perfect for me, getting homebrew up and running with a minimum of hassle.
The github project itself is basically a script that repackages just the critical chunks of xCode for distribution. In order to run that script and build the DMG files, you'd need to already have an XCode install, which would kind of defeat the point, so the pre-built DMG files are hosted on the project page.
Type g++(or make) on terminal.
This will prompt for you to install the developer tools, if they are missing.
Also the size will be very less when compared to xcode
Download Xcode, which is free with an ADC online membership (also free):
http://developer.apple.com/technology/xcode.html
xcode is now available for free from the app store. Just "buy it" (for free) and it will download. To get the command line tools go into preferences/downloads and "install command line compiler tools".
Instead of gcc you are using clang, but it works the same.
Here is how to do it on the newer mac chips and how to switch from clang(default) to g++
Install g++ through home-brew.
Check out the version you just installed, probably 12th or higher
You can make a symbolic link from g++-12 to g++
In order to do it, just type in your terminal:
sudo ln -s $(which g++-12) /usr/local/bin/g++.
Now open a new terminal and check your version again and you should see g++ instead of clang
g++ --version