gfortran compiler cannot find misspelled full directory

青春壹個敷衍的年華 提交于 2019-12-25 05:22:16

问题


I was able to make a much simpler example than the one in my original post. I'm trying to compile a fortran code using gcc version 4.9.2 (x86_64-posix-seh-rev4, Built by MinGW-W64 project) on windows.

Below is a batch script that I used to successfully compile the code:

  SET SRC_DIR=code
  gfortran -fopenmp -g -fimplicit-none -cpp ^
   %SRC_DIR%/globals/current_precision.f90^
   %SRC_DIR%/string/string.f90^
   ...
   %SRC_DIR%/user/MOONS.f90^
   parametricStudy.f90^
   -o main.exe
  del *.mod

The output looks like this:

  C:\Users\charl\Documents\GitHub\MOONS>gfortran -fopenmp -g -fimplicit-none -cpp  
  code/globals/current_precision.f90 
  code/string/string.f90 
   ...
  code/user/MOONS.f90 
  parametricStudy.f90 -o main.exe

  C:\Users\charl\Documents\GitHub\MOONS>del *.mod

Then I tried changing the source path from local to full by changing:

  SET SRC_DIR=code

to

  SET SRC_DIR=C:/Users/charl/Documents/GitHub/MOONS/code

But the output is now:

  C:\Users\charl\Documents\GitHub\MOONS>gfortran -fopenmp -g -fimplicit-none -cpp
  C:/Users/charl/Documents/GitHub/MOONS/code/globals/current_precision.f90 
   ...
  C:/Users/charl/Documents/GitHub/MOONS/code/solvers/induction/init_Bfield.f90 
  C:/Users/charl/Documents/GitHub
  gfortran: error: 
  C:/Users/charl/Documents/GitHubMOONS/code/solvers/induction/init_Sigma.f90: No such file or directory

I also tried not using variables and the same thing happened, so this seems to be related to the full path and not the use of variables. I have two questions

1) What is the reason for the error due to using the full path?

2) Why is there a misspelling in the full path? ("GitHubMOONS" should read "GitHub/MOONS")


回答1:


The reason for the error is in the setting for SRC_DIR. This has to be in DOS format i.e.

*SET SRC_DIR=C:/Users/charl/Documents/GitHub/MOONS/code*

should be

*SET SRC_DIR=C:\Users\charl\Documents\GitHub\MOONS\code*

This is same reason for the misspelling in the full path.

Using the following command in the batch file, I could compile the code successfully:

gfortran -fopenmp -g -fimplicit-none -cpp "%SRC_DIR%\globals\current_precision.f90" %SRC_DIR%\string\string.f90 %SRC_DIR%\user\MOONS.f90 parametricStudy.f90 -o main.exe

Both, the full path with filename in double quotes and without double quotes should work.




回答2:


My solution is to use relative paths for the source files. Doing so compiles fine without errors. If this somehow changes in the future, then I will update this post.

In short, just use

 SET SRC_DIR = code


来源:https://stackoverflow.com/questions/36313985/gfortran-compiler-cannot-find-misspelled-full-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!