我正在尝试编译C程序并在Vim的选项卡中显示其输出。
我的设置如下:
hellomain.c
#include<stdio.h>
#include<stdbool.h>
int main()
{
int i = 100;
bool b =0;
printf("hello world :)");
return 0;
}
makefile
program: hellomain.c
gcc -o hello hellomain.c
当我运行:make | copen
时,受此post的欢迎,我看到了这样的窗口:
gcc -o hello hellomain.c
Press ENTER or type command to continue
按回车键后,程序进行编译,我看到一个新的水平分割选项卡,其中包含gcc
命令,但不包含程序的输出:
这里是什么问题?
:make && ./hello
您尝试过这个吗?
或者,尝试以下操作
:make && ./hello | copen
首先,对于单个源文件组成的程序,无需编写Makefile(除非您使用的gnumake(mingw)版本不正确,或者如果您使用的是非gnu系统(macosx?), 。
然后,在another post中,我提出了一种编译和执行(如果编译成功的话)的方法,该方法允许注入可选输入。该解决方案需要一些脚本。
手动非自动化版本为
" Change compilation options -- required once per vim session
" in C++, it would be $CXXFLAGS...
" See the other post for more on the topic
let $CFLAGS = '-Wall -Wextra -O3'
" Compile
:make %<
:copen
" Execute
:!./%<
" or
:term ./%<