使用 gfortran 在 fortran 中编译共享对象时,我收到以下三条类似的错误消息: 我确实make HX.so
我的源代码文件夹中。这以前工作正常。我怀疑这是一个链接问题或(?)编译问题。
当我编译为可执行文件时不会出现此问题(下面的makefile标志)
制作 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
我已经在这里查看了很多关于上述错误消息的线程,但我没有得到他们提出的任何解决方案。请参阅下面的我尝试过的内容。
完成所有阅读后,我有一种预感,gcc编译器存在一些在编译时未发现的问题。但我不明白为什么。我已经安装了自制软件和Macports,并且知道这可能会搞砸路径名。以前我在安装 netcdf 库和与它们关联的其他库时遇到了问题,但是当将它们与 macports 集成并将 -I 和 -L 中的路径指向 macports 位置时,暂时编译正常。然后我不确定到底发生了什么变化.. 1)添加了一些我不记得$PATH但没有添加到./bashrc_profile? 2)也许最近的Mac更新做了一些事情..??
故障 排除:
1) 从 [this]{gcc 5 for varargs 函数的错误:后缀或操作数对"movq"无效)我假设 Xcode 酿造冲突。
所以我更新了Xcode。
2)由此我假设gcc安装之间存在冲突 我在不同的地方找到了几个 gcc 版本。(不知道为什么这与我的 gfortran copiler 有任何关系,直到我阅读了这个编辑:我现在明白这两个编译器都会给出相同的错误消息,因此我在网上找到的一些线程不会帮助我解决我的问题,而是转移我(这个(2)和下一个(3)尝试)。
3)我还将这些Xcode -gcc安装的路径添加到我的bash_profile中,希望必须使用一个。echo $PATH
产生/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
在我的/.bash_profile 中,它也说:# MacPorts Installer addition on 2018-02-21_at_11:21:44: adding an appropriate PATH variable for use with MacPorts.
..来源bash_profile,同样的错误。
仍然认为编译器的路径一定有问题,我尝试了这两件事(请记住,如果这看起来像一个有趣的解决方案,我不知道我在做什么,这些尝试可能已经导致我远离我的特定问题(?
4) 我尝试符号链接到更新的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)我尝试将 gfortran 移动到/usr/bin:
sudo mv /usr/local/bin/gfortran /usr/bin/
Password:
mv: rename /usr/local/bin/gfortran to /usr/bin/gfortran: Operation not permitted
扩展版本信息:
行为$ which gfortran
返回/usr/local/bin/gfortran
$ which gcc
和$which g++
返回/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 版本 9.2
我使用 Mac OS 10.13.3
也许其他有用的信息:
我正在使用 netcdf 动态库,我在 makefile 中指出了这些库,因为 macports 将它们放在导致链接错误的地方。我担心编译器也在那里寻找 gcc? 但实际上,我对这个主题没有足够的知识来做出任何假设。
我的制作文件的一部分:
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
编辑:
1) 使用 gfortran 使用测试文件进行正常编译可以正常工作: 测试.f90:
PROGRAM test
IMPLICIT NONE
integer :: A
A =2
WRITE(*,*)A
END PROGRAM test
$gfortran test.f90 -o test
,编译精细$./test
返回 2
2) 编译为.exe 在不同的分支中,我将所有内容保留为可执行文件;编译时一切正常。唯一改变的是(是一些声明,分配和主要不是子例程,而是主程序)。
.exe的 makefile 标志有:
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
正如@roygvib所建议的那样,我做了brew doctor
.它呈现了错误消息,我根据终端中返回的指令brew进行了修复(这包括执行brew missing
,然后按照所有指令获取缺少的库/链接现有库)
我完全专注于基于自制软件的安装,删除了Macports库。
移动的 Macports 库:sudo mv /opt/local ~/macports
检查制作 HX.so,编译时找不到 netcdf 库:f951: Warning: Nonexistent include directory ‘-I/opt/local/include/’ [-Wmissing-include-dirs]
然后,我使用自制软件安装了netcdf库: 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 ✔
我更改了makefile中的路径以指向自制netcdf库
-I/usr/local/Cellar/netcdf/4.6.0/include
-L/usr/local/Cellar/netcdf/4.6.0/lib
make HX.so 不再提供错误消息,并且 .so 在被调用时运行良好。
即使它现在已经修复,我仍然不明白的是,当(成功)编译为可执行文件时,在 makefile 中使用相同的 -I 和 -L 路径,我能够成功运行它。这个问题似乎与我如何使用共享的netcdf库与静态库有关。
我的Mac OS(10.13.2)上有brew,macport,Xcode和可能很多不干净的东西。
我在编译一个简单的c程序时遇到了这个问题:
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...
我用brew doctor
建议的以下命令解决了我的问题
sudo mv /opt/local ~/macports
echo 'export PATH="/usr/local/sbin:$PATH"' >> ~/.bash_profil
brew prune
这完全解决了我的问题。