0

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?

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • Errr, Yosemite was v10.10, Leopard was v10.5... – Mark Setchell May 15 '17 at 13:35
  • Oops! Thanks Mark. Should have said Yosemite (OS 10.10.5) – Gerry_Offer May 15 '17 at 13:39
  • Did you use `/usr/local/bin/gcc-4.9` as your compiler? What flags did you use when compiling? Have you tried compiling a trivial piece of code? Did you use `brew install gcc-XYZ --without-multilib`? – Mark Setchell May 15 '17 at 13:58
  • Thanks Mark for your help; it's much appreciated. I started with gcc-4.9 on the command line but /usr/local/bin is on my PATH. I had the same problem whether I used either -fopenmp or -Wall flags when compiling. I will try your suggestion of compiling a trivial piece of code. If I remember correctly I simply used brew install gcc@4.9 without anything else. – Gerry_Offer May 15 '17 at 14:51
  • Mark, you're clearly well onto solving my problem. Yes, when I try to compile with gcc-4.9 a simple C program with no pragmas, no GSL, no dynamic memory allocation etc I get the same stream of error messages starting with /var ! – Gerry_Offer May 15 '17 at 15:03
  • Maybe you have updated OSX without updating `Xcode`. Either run `xcode-select --install` again in Terminal, or start up `Xcode` and look for any `Update` buttons in the Preferences or About menu options. – Mark Setchell May 15 '17 at 15:05
  • I upgraded to Yosemite from OS x10.6 and then downloaded xcode 6.3. When just now I tried to run xcode 6.3, it didn't start immediately but first took several minutes to verify and then asked for additional components to download. I then used the Preferences/Downloads to update xcode. After clicking on check and download now, it said it was installing two updates and now gives a tick by xcode 6.3 which I take to mean it has done all it could. But still a stream of errors when I try to compile the simple C program with gcc-4.9. Should I be upgrading to a higher version of xcode (eg 7.2)? – Gerry_Offer May 15 '17 at 16:25
  • Please don't think I necessarily know all the answers;-) All I am suggesting is that you ensure your Xcode is as up-to-date as possible, that you have run `xcode-select --install` after upgrading Xcode, and that you re-install `gcc` with `--without-multilib` and that you re-compile and re-run your app after that. That sequence seems, by experience, to cure most ills - however parts of it may be unnecessary or redundant. Like I said, I do not **know** the answer for certain - if I did, I would put it as an actual answer rather than a comment:-) – Mark Setchell May 15 '17 at 17:39
  • Thank you, Mark. I will do all that you suggest tomorrow. – Gerry_Offer May 15 '17 at 19:24
  • I am delighted to report that when I used brew install gcc@4.9 --without-multilib the resulting gcc-4.9 compiled my C program with no error messages even with the -fopenmp flag. My grateful thanks to Mark. – Gerry_Offer May 16 '17 at 16:15
  • Excellent news! And good luck with your project. I may summarise the steps in an answer so future readers don't have to wade through the comments. – Mark Setchell May 16 '17 at 16:48
  • Good. So it wasn't a problem with my Xcode, only with my brew install. It would be good to know what the --without-multilib actually means. Thanks again, Mark. – Gerry_Offer May 16 '17 at 16:54

1 Answers1

0

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 gcc@4.9

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 gcc@4.9 --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

Community
  • 1
  • 1
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432