gfortran makefile'无法打开包含文件' [英] gfortran makefile 'can't open included file'

查看:788
本文介绍了gfortran makefile'无法打开包含文件'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了makefile编译问题,我不确定从哪里开始诊断。它是为同事的OS X系统生成的,我试图在我的Linux系统上实现它。它在OS X电脑上工作。我更新了库位置来表示它们在我的计算机上的位置 - 这可能是最大的错误来源,因为gfortran程序应该不会有所不同,不是吗?



包含的文件:file0.i,... fileN.i全都与makefile位于同一个目录中。



我确定能编译第一个目标文件,我可以通过其余的,并完成我的博士学位或拯救世界或什么。



该文件的一个片段如下:

 #%W%%G%
目录的Makefile〜/ Documents / workstuff / project / program

fflags = -O3 -I。 -I / usr / local / include -frecord-marker = 4 -free-form
## -fdefault-real-8 -fdefault-double-8
lflags = -L / usr / local / lib -lnetcdf -lnetcdff
#用于调试,使用这些选项
fflags = -g
lflags = -g
chem =〜/ Documents / workstuff / project / chem


main.o:$(chem)/code/main.f file0.i file1.i file2.i
gfortran -c $(fflags)$(chem)/ code / main .f

我收到以下错误:

 〜/ Documents / workstuff / project / program / chem / code / main.f:11:错误:无法打开包含文件'file0.i'
makefile :14:目标'main.o'的配方失败
make:*** [main.o]错误1

我认为这可能是一个可执行的问题,所以我们从644变成了744:

  username $文件file0.i 
file0.i:ASCII文本


用户名$ stat -c'%A%a%n'file0.i
-rwxr-- r-- 744 file0.i

仍然同样e RROR。仔细检查我的标志是否指向正确的位置:

 用户名$ nf-config --fflags 
- I / usr / local / include
用户名$ nf-config --flibs
-L ​​/ usr / local / lib -lnetcdff -lnetcdf -lnetcdf

对于它的价值,file0.i包含以下内容,我当然在网上分享了无意义的数字:

  $ Id:file0.i,v 1.12 2012/12/31 04:25:23 username Exp $ 
PARAMETER(NLT = 19,NHT = 51 ,DZETA = 0.5 / 3,Psurf = 100)
PARAMETER(NLT1 = NLT + 1,NHT1 = NHT + 2,NLT2 = 3 * NLT + 1,NHT2 = 4 * NHT + 1)
参数(NDIST = 111,TD1 = 110.,NVC = 1,NVSP = 1,n = 1,n = NVTIME = 3)


<我不知道 gfortran 非常好,所以我可能完全错误,但是对于 gcc ,如果一个C源文件包含:

  #include< foo.h> 

如果 gcc 用<$将在与源文件相同的目录中搜索c $ c> -I。, foo.h ,而不是在您调用的目录中 gcc 自。示例:

  $ ls foo 
bar.c bar.h
$ cat foo / bar.c
#include< bar.h>

int main(int argc,char ** argv){
return 0;
}
$ gcc -I。 foo / bar.c
foo / bar.c:1:10:错误:'bar.h'文件未找到< angled>包括;使用引号代替
#include< bar.h>
^ ~~~~~~
bar.h
1生成的错误。
$ gcc -Ifoo foo / bar.c
$

所以,它可能是你应该把你的头文件放在与你的源文件相同的目录下,或者使用 -I 其中< path> / code>是您呼叫 gfortran 的绝对路径。


I'm having an issue with a makefile compiling and I'm not sure where to start diagnosing this. It was generated for a colleague's OS X system, and I'm trying to implement it on my linux system. It worked on the OS X computer. I've updated library locations to represent where they live on my computer - and this is likely the biggest source of error, as gfortran procedure shouldn't be different, no?

The included files: file0.i, ... fileN.i all live in the same directory as the makefile.

I'm certain if I could compile the first object file I could get through the rest and complete my PhD or save the world or something.

A snippet of the file follows:

#  %W%  %G%
#  Makefile for directory ~/Documents/workstuff/project/program         
#
fflags = -O3 -I. -I/usr/local/include -frecord-marker=4 -ffree-form
##     -fdefault-real-8 -fdefault-double-8
lflags = -L/usr/local/lib -lnetcdf -lnetcdff
#  for debugging, use these options
fflags = -g
lflags = -g
chem = ~/Documents/workstuff/project/chem      


main.o: $(chem)/code/main.f file0.i file1.i file2.i
    gfortran -c $(fflags) $(chem)/code/main.f

And I receive the following error:

~/Documents/workstuff/project/program/chem/code/main.f:11: Error: Can't open included file 'file0.i'
makefile:14: recipe for target 'main.o' failed
make: *** [main.o] Error 1

I thought it might be an executable issue, so we went from 644 to 744:

username$ file file0.i
file0.i: ASCII text


username$ stat -c '%A %a %n' file0.i
-rwxr--r-- 744 file0.i

Still same error. Double-check that my flags are pointing to the right place:

username$ nf-config --fflags
-I/usr/local/include
username$ nf-config --flibs
-L/usr/local/lib -lnetcdff -lnetcdf -lnetcdf

For what its worth, file0.i contains the following, which I have of course filled with nonsense numbers for sharing online:

 $Id: file0.i,v 1.12 2012/12/31 04:25:23 username Exp $
  PARAMETER (NLT=19,NHT=51,DZETA=0.5/3.,Psurf=100.)
  PARAMETER (NLT1=NLT+1,NHT1=NHT+2,NLT2=3*NLT+1,NHT2=4*NHT+1)
  PARAMETER (NDYEAR=33,NTN=75,NTCV=14,NLV=21,NPOL=8,NGSP=3)
  PARAMETER (NDIST=111,TD1=110.,NVC=1,NVSP=1,NVTIME=3)

Does anything obvious stick out to anyone?

解决方案

I do not know gfortran very well, so I may be completely wrong, but for gcc, if a C source file contains:

#include <foo.h>

and if gcc is called with -I., foo.h will be searched in the same directory as the source file, not in the directory where you call gcc from. Example:

$ ls foo
bar.c   bar.h
$ cat foo/bar.c
#include <bar.h>

int main(int argc, char **argv) {
  return 0;
}
$ gcc -I. foo/bar.c
foo/bar.c:1:10: error: 'bar.h' file not found with <angled> include; use "quotes" instead
#include <bar.h>
         ^~~~~~~
         "bar.h"
1 error generated.
$ gcc -Ifoo foo/bar.c
$

So, it could be that you should put your header files in the same directory as your source file or use a -I<path> where <path> is the absolute path of where you call gfortran from.

这篇关于gfortran makefile'无法打开包含文件'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆