指定gfortran应寻找模块的目录 [英] Specify directory where gfortran should look for modules

查看:174
本文介绍了指定gfortran应寻找模块的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在编译基于模块的程序(例如依赖于模块 bar 的主程序 foo ),如下:

  gfortran -c bar.f90 
gfortran -o foo.exe foo.f90 bar.o

foo.f90 和<$ c时, $ c> bar.f90 位于同一个目录中。当我在<$ c $中调用 use bar 时,如何指定gfortran应该查找 bar.o 的目录C> foo.f90 ? (即我不想指定编译器应特别链接 bar.o ,我只是希望它能够找到它。)


你可以通过 -I 编译器来告诉gfortran你的模块文件(.mod文件)的位置旗。另外,可以通过 -J 编译器标志告诉编译器将编译模块放在哪里。请参阅 gfortran手册页中的目录搜索选项一节。



我使用这些将我的对象(.o文件)和我的模块文件放在同一个目录中,但放在与我所有源文件不同的目录中,所以我不会混乱上我的源代码目录。例如,

  SRC = / path / to / project / src 
OBJ = / path / to / project / obj
BIN = / path / to / project / bin

gfortran -J $(OBJ)-c $(SRC)/bar.f90 -o $(OBJ)/bar.o
gfortran -I $(OBJ)-c $(SRC)/foo.f90 -o $(OBJ)/foo.o
gfortran -o $(BIN)/foo.exe $(OBJ) /foo.o $(OBJ)/bar.o

尽管上面看起来很费力在命令行输入,我通常在我的makefile中使用这个想法。



仅供参考,等效的英特尔fortran编译器标志是 - 我 - 模 。基本上,ifort用 -module 替换 -J 选项。请注意,模块之后有一个空格,但不是在J之后。


I currently compile programs based on modules (such as main program foo which depends on module bar) as follows:

gfortran -c bar.f90
gfortran -o foo.exe foo.f90 bar.o

This works fine when foo.f90 and bar.f90 are in the same directory. How do I specify a directory where gfortran should look for bar.o when I call use bar in foo.f90? (i.e. I don't want to specify that the compiler should link bar.o specifically, I just want it to go find it.)

解决方案

You can tell gfortran where your module files (.mod files) are located with the -I compiler flag. In addition, you can tell the compiler where to put compiled modules with the -J compiler flag. See the section "Options for directory search" in the gfortran man page.

I use these to place both my object (.o files) and my module files in the same directory, but in a different directory to all my source files, so I don't clutter up my source directory. For example,

SRC = /path/to/project/src
OBJ = /path/to/project/obj
BIN = /path/to/project/bin

gfortran -J$(OBJ) -c $(SRC)/bar.f90 -o $(OBJ)/bar.o
gfortran -I$(OBJ) -c $(SRC)/foo.f90 -o $(OBJ)/foo.o
gfortran -o $(BIN)/foo.exe $(OBJ)/foo.o $(OBJ)/bar.o

While the above looks like a lot of effort to type out on the command line, I generally use this idea in my makefiles.

Just for reference, the equivalent Intel fortran compiler flags are -I and -module. Essentially ifort replaces the -J option with -module. Note that there is a space after module, but not after J.

这篇关于指定gfortran应寻找模块的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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