g ++致命错误,无此文件或目录 [英] g++ fatal error no such file or directory
问题描述
所以我正在使用 gvim编辑器在C ++中进行编程,但是当我打开一个在编辑器上的.cpp
文件,然后键入:!g++ -std=C++17 file.cpp -o file
我收到此错误:
请参阅下面的附件:
So I am using the gvim editor to program in C++, however when I open a .cpp
file on the editor then type :!g++ -std=C++17 file.cpp -o file
I get this error:
See attached file below:
C:\Windows\system32\cmd.exe /c(g++ -std=c++17 file.cpp - o file)
g++: error: file.cpp: No such file or directory
g++: fatal error: no input files
compilation terminated
现在这与vim或我的命令有关吗?
Now is this related to vim, or to my command?
谢谢.
推荐答案
您似乎不幸地使用了gcc-mingw,而gcc-mingw并没有正确配置gnumake(否则:let $CXXFLAGS='-std=c++17 -Wall -Werror'
+ make %<
就足够了).因此,您将需要手动执行一些操作.并且不要将参数错误拼写为g ++.忘了:!{compilername}
,这就是我们要在25年前用vi做的事情.与vi不同,vim允许集成编译.
It seems that you're unfortunately using gcc-mingw that doesn't come with gnumake properly configured (:let $CXXFLAGS='-std=c++17 -Wall -Werror'
+ make %<
would have been enough otherwise). Thus you'll have a do a few things manually. And don't misspell the parameters to g++. And forget :!{compilername}
, this is want we had to do 25 years ago with vi. Unlike vi, vim permits to integrate compilation.
" to do once
:let &makeprg='g++ -std=c++17 -Wall -Werror % -o %<'
" to execute each time to compile
:make
:copen
" to navigate the errors
:cc " jump to error under cursor
:cnext " jump to next error
:cprev " jump to previous error
:cclose " close the quickfix window
-> :h quickfix
这不应从错误的目录执行g ++.如果还是这样,请运行:cd %:h
.
This shouldn't execute g++ from the wrong directory. If this still does, run :cd %:h
.
执行应与:./%
一起使用.
如果您希望为此使用热键...
And if you wish to have hot keys for that...
nnoremap <silent> <F7> :<c-u>update<cr>:make<cr>
nnoremap <silent> <C-F5> :<c-u>./%<cr>
nnoremap <silent> <F3> :<c-u>cnext<cr>
nnoremap <silent> <S-F3> :<c-u>cprev<cr>
仅在出现错误时自动打开快速修复程序窗口,或者仅在没有错误时才自动执行结果,这需要更多的工作.
Automatically opening the quickfix windows only if there are errors or executing the result only if there are no errors requires a little more work.
这篇关于g ++致命错误,无此文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!