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 gcc
and $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