Can't compile with gcc-4.9

357 Views Asked by At

I eventually want to use valgrind to find what is causing the occasional bizarre output in a C program which refines a model against experimental data using OpenMP parallel programming.

To avoid the use of the nominal gcc (ie clang) compiler, I used brew to install gcc-4.9 on my MacPro running Yosemite (OS x 10.10.5). However, when trying to compile my program with gcc-4.9, with or without -fopenmp, I get numerous error messages of the type:

/var/folders/qc/1j0gr_l48xnfd9001s6tt6f80000gn/T//ccRxnrnU.s:30597:suffix or operands invalid for `movq'

I have no idea what the problem triggering these error messages is. Can anyone help?

1

There are 1 best solutions below

0
On

The following summarises what was worked out in the comments section and did lead to the issue being resolved. Not all steps may be necessary, but most are probably good practice.


Step 1 - Clean up

If you have been trying lots of different, potentially incompatible, methods to get OpenMP set up, it is probably a good idea to clean them up first. So, something like:

brew rm --force gcc           # or maybe [email protected]

Step 2 - Update Xcode and Command Line Tools

If you have upgraded macOS since installing Xcode, it is probably advisable to update Xcode and its "Command Line Tools"

Consider uninstalling and re-installing Xcode - it is available for free from the App Store.

Update/install the "Command Line Tools" after installing/updating with:

xcode-select --install

Step 3 - Install gcc

Now, try installing gcc afresh, ensuring that you use the --without-multilib option:

brew install [email protected] --without-multilib

Hopefully you can now compile OpenMP code with:

/usr/local/bin/gcc -fopenmp program.c -o program

I am unsure exactly why the --without-multilib option is needed and prefer to quote @hristo-iliev:

Multilib usually refers to the coexistence of both 64-bit and 32-bit versions of each library so that 32-bit software could be run on 64-bit OS. In the GCC case that probably refers to having all GCC runtime libraries in "fat" Mach-O format, i.e. versions for both i386 and x86_64 in the same shared library file. It could be that libgomp (the GNU OpenMP runtime library) cannot be built in such a way.

See this question.

Keywords: gcc, g++, GNU Compiler, OpenMP, fopenmp, -fopenmp, Xcode, multilib, Command Line Tools, macOS, OSX, homebrew, brew