vim ftplugin无法链接可执行文件

时间:2015-07-04 20:37:29

标签: vim compilation linker fortran

我正为vim撰写ftplugin fortran

"global values
let s:Compiler  =   'gfortran'
let s:ObjExt    =   '.o'
let s:ModExt    =   '.mod'
let s:ExeExt    =   '.run'
let s:VimComp   =   'gfortran'
let s:FCFlags   =   '-Wall -g -O0 -c'
let s:FLFlags   =   '-Wall -g -O0'
let s:OutputGvim=   'vim'

" Compile: compile the current file
function! Compile()

  exe ":cclose"
  exe ":update"

  let sou = expand("%:p")
  let obj = expand("%:p:r").s:ObjExt

  if !filereadable(obj) || (filereadable(obj) && (getftime(obj)<getftime(sou)))
    let makeprg_saved = '"'.&makeprg.'"'
    exe "setlocal makeprg=".s:Compiler
    let v:statusmsg = ''
    exe "make ".s:FCFlags. " " .sou. " -o " .obj
    if empty(v:statusmsg)
      :let &statusline = "'".obj."':Compiled successfully"
    endif
    if v:shell_error !=0
      :let &statusline = v:shell_error
    endif
    :redraw!
    exe ":botright copen"
  else
    :let &statusline = "'".obj."':is up to date"
  endif
endfunction

" Link: Compile and link 
function! Link()
  "compile first
  call Compile()
  let sou = expand("%:p")
  let obj = expand("%:p:r").s:ObjExt
  let exe = expand("%:p:r").s:ExeExt

  if filereadable(exe)                      &&
        \ filereadable(obj)                 &&
        \ filereadable(sou)                 &&
        \ (getftime(exe) >= getftime(obj))  &&
        \ (getftime(obj) >= getftime(sou))
    :let &statusline = " '".exe."' is up to date "
    return
  endif

  let v:statusmsg = ""
    let makeprg_saved = '"'.&makeprg.'"'
    exe "setlocal makeprg=".s:Compiler
 "#######################################
 "Expect to create the executable here
  silent exe "make " .s:FLFlags." ".obj. " -o " .exe
 "#######################################
  if empty(v:statusmsg)
    :let &statusline="'".exe."': Successfully Linked"
    redraw!
    exe ":botright cwindow"
  else
    exe ":botright copen"
  endif
endfunction

第一个函数(Compile)创建目标文件,第二个函数(Link)首先调用Compile,然后链接文件以创建可执行文件。

问题是,对于一个新代码,比如hello.f90,在没有创建任何目标文件的情况下,我运行Link(),希望Link首先调用Compile(它正在做什么)和链接可执行文件在行

silent exe "make " .s:FLFlags." ".obj. " -o " .exe

但它并没有创造出来。对于全新运行,仅创建.o个文件。如果我重新运行Link()(现在,.o已存在),则会创建可执行文件。

但我没有看到为什么在第一次运行中没有创建可执行文件的原因。

请帮助。

NB。对于不熟悉fortran的vimmers,一个简单的hello.f90是:

!File=hello.f90
Program hello
  Implicit None
  write(*,*) "Hello World"
End Program hello

gfortrangnu fortran compiler

0 个答案:

没有答案