3

When I ask which version of gcc I have, I get the following:

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.1.0 (clang-902.0.39.2)
Target: x86_64-apple-darwin17.6.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

When I try to get information about gcc: ls -la /usr/bin |grep gcc

I get:

-rwxr-xr-x     1 root   wheel     18288 May 29  2018 gcc
-rwxr-xr-x     1 root   wheel      2043 Sep 26  2016 gccmakedep
lrwxr-xr-x     1 root   wheel         5 Mar 28  2018 llvm-gcc -> clang

I am using MacOS 10.13.5, and the reason that I want to use gcc instead of clang is because I have code I want to run in MATLAB that is in C, but I can't compile the code with clang, because fopenmp is unsupported.

When I try to compile just the matlab part of the program so that I can run it with a matlab interface:

make matlab

I get the following error:

gcc -std=c99 -pedantic -Wall -O3 -fopenmp -DSSHT_VERSION=\"1.2b1\"...

clang: error: unsupported option '-fopenmp'

I used the link: Installed gcc with Homebrew, now how to use that gcc instead of clang?

export PATH=/usr/bin
export CXX=/usr/local/Cellar/gcc/8.2.0/bin/g++-8
export CC=/usr/local/Cellar/gcc/8.2.0/bin/gcc-8

to my code.

bmike
  • 235,889
  • Welcome to Ask Different. - This gets asked quite a bit so forgive me for presuming you are using the built in gcc which calls clang to act like gcc instead of being gcc - If so, does this answer your entire question? https://apple.stackexchange.com/questions/245891/installed-gcc-with-homebrew-now-how-to-use-that-gcc-instead-of-clang?rq=1 – bmike Jan 14 '19 at 19:49
  • The version of gcc I have is from homebrew. It is 8.2.0. I tried the solution in that link prior to posting this, but it did not work for me. – StatsBrooklyn Jan 14 '19 at 21:49
  • Perfect - I would make a small edit - say you used the link (in the body) to get gcc (and show your path to gcc / version) if you want to reinforce that. Not everyone will see the comments. Glad I didn't close as dupe on an assumption / presumption. Nice problem - I hope the collective "we" can help – bmike Jan 14 '19 at 21:51
  • Ok. Thank you. I'm obviously very new to this. I will edit. I have also found a similar solution, so maybe this is a dupe. – StatsBrooklyn Jan 14 '19 at 21:52
  • I added: export PATH=/usr/bin export CXX=/usr/local/Cellar/gcc/8.2.0/bin/g++-8 export CC=/usr/local/Cellar/gcc/8.2.0/bin/gcc-8 – StatsBrooklyn Jan 14 '19 at 21:53
  • You don't happen to know if I can add a path for a mex.h file, which is needed and not found in the rest of my code, do you? – StatsBrooklyn Jan 14 '19 at 21:58
  • @StatsBrooklyn paths for a mex.h file will be a -I parameter to gcc but this will e in your build script and not set from the command line (as will the path to gcc) – mmmmmm Jan 15 '19 at 13:44
  • What is your build script/makefile ? – mmmmmm Jan 15 '19 at 13:46
  • @Mark My makefile is to compile a Fast spin spherical harmonic transforms program (ssht) that is supposed to interface with Matlab. see github.com/astro-informatics/ssht. However, I finally got it to compile past the mex part, which I also specified in the path. But it is still not finding the mex files within the ssht program in MATLAB, so something is still wrong. I kind of don't know where to start at this point. I'm still getting a compile error: make: *** [/Users/.../Code/ssht-public/src/matlab/ssht_forward_mex.mexmaci64] Error 255. – – StatsBrooklyn Jan 16 '19 at 14:30

2 Answers2

2

Apple and xcode do not provide gcc. Any file called gcc us a link to clang

You need to install gcc from a third party and also check the version has mp enabled.

The easiest way is to install gcc using a package manager like macports, homebrew or fink.

mmmmmm
  • 30,160
  • Mark - would there be a way to pass the mp enable to brew so that it gets compiled in? I'm super rusty on gcc and don't want to assign homework - but if you happened to just know... – bmike Jan 14 '19 at 21:52
  • I had to directly specify the path of my gcc in the code, but it worked: – StatsBrooklyn Jan 14 '19 at 21:57
  • @bmike - I am not a Homebrew expert but dosn't brew just install programs. So it just adds a program e.g gcc to the $PATH – mmmmmm Jan 15 '19 at 00:41
  • It can compile from source and only if you choose the default options does it download a pre build package. In the past, when I needed ssl support in mongodb I had to pass -withssl to the brew to have it add those compile flags. https://askmhs.blogspot.com/2016/11/how-to-install-and-configure-mongodb-in_23.html In this case, my question is a side issue since I misunderstood the ask. It's simply how to change the path and send the alternate path to build scripts if I understand it better now. – bmike Jan 15 '19 at 03:24
  • Any ideas on this one:

    Separate complex matrix function mxGetPi was called. Either update the source code for interleaved complex, or rerun MEX with the -R2017b command line option to use the R2017b API with compatibility support. For more information, see Interleaved Complex make: *** [/Users/.../Dropbox/Code/ssht-public/src/matlab/ssht_forward_mex.mexmaci64] Error 255 I'm running MATLAB2018a. I don't even understand what the reference to R2017b is referring to.

    – StatsBrooklyn Jan 16 '19 at 14:27
  • That requires more knowledge of matlab specifics then I'll think you will find here. Either lo in macports or homebrew to see if they have done a port or ask on matlab support areas. – mmmmmm Jan 16 '19 at 14:43
  • although my guess on R2017b is you are compiling the code with the old API and so need that parameter or compile with new options. In either case this looks like you need to study mr Matlab documentation as to how to compile extentions. – mmmmmm Jan 17 '19 at 21:53
-1

Having gcc installed with homebrew, directly point to the where it is installed in the beginning of the code to compile (makefile):

export CXX=/usr/local/Cellar/gcc/8.2.0/bin/g++-8
export CC=/usr/local/Cellar/gcc/8.2.0/bin/gcc-8