1

When compiling a shared object in fortran with gfortran, I get the following three similar error messages: I do make HX.so in the folder with my source code. This used to work fine before. I suspect this is a linking issue or(?) compiling issue.

The problem does not occur when I compile as executable (makefile flags below)

output during make HX.so:

/var/folders/g0/dlhhqpcj18x3d99m9htxjn6w0000gn/T//cc5UxkcK.s:81:suffix or operands invalid for `movq'
/var/folders/g0/dlhhqpcj18x3d99m9htxjn6w0000gn/T//cc5UxkcK.s:213:suffix or operands invalid for `movq'
/var/folders/g0/dlhhqpcj18x3d99m9htxjn6w0000gn/T//cc5UxkcK.s:269:suffix or operands invalid for `movq'
/var/folders/g0/dlhhqpcj18x3d99m9htxjn6w0000gn/T//cc5UxkcK.s:350:suffix or operands invalid for `movq'
make: *** [CARBON.o] Error 1

I have looked at so many threads here about the above error message, but I don't get any of their proposed solutions to work..see below for what I have tried.

With all the readings done I have a hunch that there is some problems with the gcc compiler that is not found when compiling. But I cannot understand why. I have homebrew and Macports installed and understand that this can screw up the pathnames. Previously I had problems getting the netcdf libraries and other libraries associated with them installed , but when intalling them with macports and pointing the paths in -I and -L to the macports locations, temporarily things compiled fine. Then I am not sure what exactly changed.. 1) added something I cannot remember to $PATH but not to the ./bashrc_profile? 2) Maybe a recent mac update has done something..??

Troubleshooting:

1) from [this]{error with gcc 5 for varargs function: suffix or operands invalid for `movq') I hypothesised an Xcode brew conflict.

So I updated Xcode.

2) From this I hypothesised that there is a conflict between gcc installations I found several gcc versions in various places. ( not knowing why this has anything to do with my gfortran copiler, until I read this Edit: I now understand that both these compilers will give the same error message and therefore some of the threads I found online would not help me for my problem but rather divert me from it (this(2) and the next( 3) attempt).

3) I also added the paths to these Xcode -gcc installations to my bash_profile, hoping that one must be used.. echo $PATH yields /usr/local/opt/gettext/bin:/usr/local/bin:/opt/local/bin:/opt/local/sbin:/Users/../anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin:/Applications/Xcode.app/Contents/Developer/usr/bin In my /.bash_profile it also sais: # MacPorts Installer addition on 2018-02-21_at_11:21:44: adding an appropriate PATH variable for use with MacPorts. .. sourced bash_profile, same error.

Still thinking that there must be an issue with the paths of the compilers I tried these two things ( please bear in mind, if this looks like a funny solution, I don't know what I am doing and these attempts might have been leading me away from my specific problem(?))

4) I tried symlinking to the updated Xcode gcc:

 sudo ln -s /Applications/Xcode.app/Contents/Developer/usr/bin/gcc /usr/bin/g++
Password:
ln: /usr/bin/g++: Operation not permitted

5)I tried moving gfortran to /usr/bin:

sudo mv /usr/local/bin/gfortran /usr/bin/
Password:
mv: rename /usr/local/bin/gfortran to /usr/bin/gfortran: Operation not permitted

Extended version information:

doing $ which gfortran returns /usr/local/bin/gfortran $ which gccand $which g++ returns /usr/bin/gcc or g++

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

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

$gfortran --version
GNU Fortran (GCC) 6.1.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ld -v
@(#)PROGRAM:ld  PROJECT:ld64-274.2
configured to support archs: i386 x86_64 x86_64h armv6 armv7 armv7s armv7m armv7k arm64 (tvOS)
LTO support using: LLVM version 5.0.1

$as -v
Apple Inc version cctools-895, GNU assembler version 1.38

Xcode version Version 9.2

I use Mac OS 10.13.3

Maybe additional useful information:

I am using netcdf dynamic libraries, which I point to in my makefile, because macports put them in a place that caused linking errors. I am worried that the compiler is also looking for gcc there? But really, I don't have enough knowledge on this topic to make any hypotheses.

part of my makefile:

F90 = gfortran
FFLAGS = -O2 -fpic -g -I/opt/local/include/ -fdefault-real-8   # -I/opt/local/include/  -check -traceback  # double-precision now run in Fortran , -fpic for creating shared object file
LDFLAGS = -L/opt/local/lib/ -lnetcdff  -shared   #-shared, for creating a shared object file

edit:

1) a normal compilation with a testfile using gfortran works fine: test.f90:

PROGRAM test
IMPLICIT NONE
integer :: A
A =2
WRITE(*,*)A
END PROGRAM test

$gfortran test.f90 -o test, compiles fine $./test returns 2

2) Compiling as .exe In a different branch, where I keep everything as executable; when compiling all works fine. The only thing that changes ( are a few declarations, allocations and the main not being a subroutine, but the main program).

makefile flags for .exe there are:

F90 = gfortran FFLAGS = -O2 -g -I/opt/local/include/ #-check -traceback # double-precision now run in Fortran , -fpic for creating shared object file LDFLAGS = -L/opt/local/lib/ -lnetcdff #-shared, for creating a shared object file

  • I don't think this is a code issue. The code used to compile fine before. I think it is a compiling or linking issue. – Annemarie Eckes Mar 07 '18 at 15:42
  • are these things I added the necessary binutils information? Okay, I will try to simplify this code but it is just so complex I don't know where to start. – Annemarie Eckes Mar 07 '18 at 16:05
  • It seems to be all in the carbon.f90. Can't you make a simpler example from this file? Can you verify the problem is in this file? Notice it happens **before** any linking, but probably during translation of the assembly to machine code. – Vladimir F Героям слава Mar 07 '18 at 16:23
  • I know, I haven't touched this file though and the only suspicious thing might be in the other subroutine it USES .. But I will have another look – Annemarie Eckes Mar 07 '18 at 16:26
  • Does "brew doctor" possibly give some warning message? (not sure but just looked at [this](https://github.com/Homebrew/legacy-homebrew/issues/45258) page) – roygvib Mar 07 '18 at 16:43
  • it does. it recommends doing `brew missing`. when doing that, I get `wget: gettext libunistring libidn2`. checking what this means now.. – Annemarie Eckes Mar 07 '18 at 16:49
  • Do you possibly have gfortran installed both from Homebrew and Macports? (Makefile seems to assume Macports (/opt/local/include), while "which gfortran" points to /usr/local/bin, so a bit inconsistent?) It might be useful to re-check .bashrc and .bash_profile (for search path) – roygvib Mar 07 '18 at 17:23
  • some of the above were present but unlinked. [this thread helped me overcome these issues] (https://stackoverflow.com/questions/26647412/homebrew-could-not-symlink-usr-local-bin-is-not-writable) But.. I think I am running in circles. It seems to be a conflict between macport and homebrew. now I have removed macport as was suggested in the error message I received ( ~sudo mv /opt/local ~/macports), but when compiling I receive my previous netcdf- error messages. the netcdf libraries must have been removed. I am running in circles (: – Annemarie Eckes Mar 07 '18 at 17:27
  • @roygvib ,yes I noticed that.. I don't really know where things need to be located and why. The troubleshooting time I spent on this I could have probably learned about it. I put the (/opt/local/include)in for the makefile, to overcome a netcdf dynamic library issue I ran into.So you are saying the compiler also needs to be located in this directory?Was able to run my code having this path in my makfile before though.don't know what changed.. 1) added something I cannot remember to $PATH but not to the ./bashrc 2) Maybe a recent mac update has done something..?? – Annemarie Eckes Mar 07 '18 at 17:32
  • If gfortran (from /usr/local/bin, Homebrew) cannot find the pre-compiled netcdf library, it may be sufficient to modify "-L/opt/local/lib/ -lnetcdff -shared" appropriately (e.g., place libnetcdf.a in your home directory and set -L/Users/yourname). It might also be necessary to re-compile netcdf library itself with gfortran from Homebrew (not sure because I have no experience with Netcdf...) I think it will be useful to summarize the updated situation as "Update" in the question (for the readers to follow the situation). (Also you can do "echo $PATH" to see your current PATH value.) – roygvib Mar 07 '18 at 17:36
  • okay, thanks!! will try this now. `echo $PATH` yields `/usr/local/opt/gettext/bin:/usr/local/bin:/opt/local/bin:/opt/local/sbin:/Users/annemarieeckes/anaconda/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/opt/X11/bin:/Applications/Xcode.app/Contents/Developer/usr/bin`. In my /.bash_profile it also sais `# MacPorts Installer addition on 2018-02-21_at_11:21:44: adding an appropriate PATH variable for use with MacPorts. export PATH="/opt/local/bin:/opt/local/sbin:$PATH"` – Annemarie Eckes Mar 07 '18 at 17:39

2 Answers2

3

As suggested by @roygvib I did brew doctor. It rendered error messages, which I fixed guided by the instructions brew returned in my terminal ( this included doing brew missing and then following all instructiong to obtain missing libraries / linking existing libraries)

focusing entirely on homebrew-based installations, I removed macports libraries.

moved macports libraries: sudo mv /opt/local ~/macports

checking a make HX.so and the netcdf-libraries were not found when compiling: f951: Warning: Nonexistent include directory ‘-I/opt/local/include/’ [-Wmissing-include-dirs]

Then, I installed netcdf libraries using homebrew: brew install netcdf --with-fortran

$ brew info netcdf
netcdf: stable 4.6.0 (bottled)
Libraries and data formats for array-oriented scientific data
https://www.unidata.ucar.edu/software/netcdf
/usr/local/Cellar/netcdf/4.6.0 (84 files, 6MB) * 
Poured from bottle on 2018-03-08 at 07:28:02
From: https://github.com/Homebrew/homebrew-core/blob/master/Formul /netcdf.rb
==> Dependencies
Build: cmake ✘
Required: hdf5 ✔, gcc ✔

I changed the paths in my makefile to point to the homebrew netcdf libraries

-I/usr/local/Cellar/netcdf/4.6.0/include -L/usr/local/Cellar/netcdf/4.6.0/lib

make HX.so gives no more error messages and the .so runs fine when being called.

Even though it is fixed now, what I still don't understand is that when (successfully) compiling as executable, with the same -I and -L paths in the makefile, I was able to successfully run it. The issue seems to be related to how I was using the shared netcdf libraries vs the static libraries.

0

I have brew, macport, Xcode and possibly a lot of unclean stuff on my Mac OS (10.13.2).

I had this problem when compiling a simple c program:

Accfermi $ gcc acc_fermi_jg.c -o acc
/var/folders/w2/p1_q71lx3ll42j4h4lq28ljr0000gn/T//ccCCVWTZ.s:15:suffix or operands invalid for `movq'
/var/folders/w2/p1_q71lx3ll42j4h4lq28ljr0000gn/T//ccCCVWTZ.s:16:suffix or operands invalid for `movq'
/var/folders/w2/p1_q71lx3ll42j4h4lq28ljr0000gn/T//ccCCVWTZ.s:52:suffix or operands invalid for `movq'
/var/folders/w2/p1_q71lx3ll42j4h4lq28ljr0000gn/T//ccCCVWTZ.s:53:suffix or operands invalid for `movq'
etc...

I fixed my problem with the following commands suggested by brew doctor

sudo mv /opt/local ~/macports
echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profil
brew prune

This completely fixed my problem.