vim菜鸟

Vim、Emacs配置和使用
回复
李伟武
帖子: 28
注册时间: 2008-03-07 1:11

vim菜鸟

#1

帖子 李伟武 » 2008-03-09 11:12

在vim 下编写C程序
#include<stdio.h>
void main(void)
{
printf("ubuntu");
}
在命令模式下输入地:make
之后提示:make: *** 没有指明目标并且找不到 makefile。 停止。
这个问题怎么解决呀??
岁月催人!
dbzhang800
帖子: 3182
注册时间: 2006-03-10 15:10
来自: xi'an China
联系:

#2

帖子 dbzhang800 » 2008-03-09 11:29

用make之前要先写makefile。

一个文件的话,直接gcc编译就好了
http://wiki.ubuntu.org.cn/gcchowto
李伟武
帖子: 28
注册时间: 2008-03-07 1:11

别笑话

#3

帖子 李伟武 » 2008-03-09 11:34

用gcc怎么编译呀?是直接在命令模式下输入:gcc吗?问题太菜了,别笑话哦!@
岁月催人!
头像
newman0708
帖子: 188
注册时间: 2007-09-22 13:09

#4

帖子 newman0708 » 2008-03-09 11:56

这样就可以了
$ gcc -o hello hello.c
chmod +x ./hello
./hello
dbzhang800
帖子: 3182
注册时间: 2006-03-10 15:10
来自: xi'an China
联系:

Re: 别笑话

#5

帖子 dbzhang800 » 2008-03-09 12:34

李伟武 写了:用gcc怎么编译呀?是直接在命令模式下输入:gcc吗?问题太菜了,别笑话哦!@
vim命令模式执行外部命令 加"!"

代码: 全选

:!gcc -Wall % -o %<
w3484732
帖子: 36
注册时间: 2007-05-11 19:48
来自: 湖北襄樊

第一个C程序问题

#6

帖子 w3484732 » 2008-03-10 20:16

我一直都不能完成最基本的C程序!
我想输入一个简单的C程序HELLO WORLD
是这样编译的:
#include <stdio.h>

int main()
{
printf("Hello, world!\n");
return 0;
}

存为并退出:hello.c
在终端输入:gcc -o hello.c vi.c回车
出现:
wangxuyuan@wangxuyuan-laptop:~$ gcc -o hello.c vi.c
gcc: vi.c:No such file or directory
gcc: 没有输入文件
wangxuyuan@wangxuyuan-laptop:~$

这是怎么回事阿,大家能看看我是那里出错了?
C程序我在很多地方找到的都不一样!这是怎么回事?
如:我在书上看到的:
#include<iostream>

int main()
{
std::cout<<"hello world!\n;
return 0;
}
dbzhang800
帖子: 3182
注册时间: 2006-03-10 15:10
来自: xi'an China
联系:

Re: 第一个C程序问题

#7

帖子 dbzhang800 » 2008-03-10 20:48

w3484732 写了:我一直都不能完成最基本的C程序!
我想输入一个简单的C程序HELLO WORLD
是这样编译的:
#include <stdio.h>

int main()
{
printf("Hello, world!\n");
return 0;
}

存为并退出:hello.c
在终端输入:gcc -o hello.c vi.c回车
出现:
wangxuyuan@wangxuyuan-laptop:~$ gcc -o hello.c vi.c
gcc: vi.c:No such file or directory
gcc: 没有输入文件
wangxuyuan@wangxuyuan-laptop:~$

这是怎么回事阿,大家能看看我是那里出错了?
C程序我在很多地方找到的都不一样!这是怎么回事?
如:我在书上看到的:
#include<iostream>

int main()
{
std::cout<<"hello world!\n;
return 0;
}
另一帖子中回复你了
diskdriver
帖子: 21
注册时间: 2006-12-21 8:45

Re: vim菜鸟

#8

帖子 diskdriver » 2008-03-13 10:05

李伟武 写了:在vim 下编写C程序
#include<stdio.h>
void main(void)
{
printf("ubuntu");
}
在命令模式下输入地:make
之后提示:make: *** 没有指明目标并且找不到 makefile。 停止。
这个问题怎么解决呀??
直接make + 文件名前部分(去掉".c")
Furson
帖子: 24
注册时间: 2008-03-30 15:37

Re: 第一个C程序问题

#9

帖子 Furson » 2008-04-12 12:51

w3484732 写了:我一直都不能完成最基本的C程序!
我想输入一个简单的C程序HELLO WORLD
是这样编译的:
#include <stdio.h>

int main()
{
printf("Hello, world!\n");
return 0;
}

存为并退出:hello.c
在终端输入:gcc -o hello.c vi.c回车
出现:
wangxuyuan@wangxuyuan-laptop:~$ gcc -o hello.c vi.c
gcc: vi.c:No such file or directory
gcc: 没有输入文件
wangxuyuan@wangxuyuan-laptop:~$

这是怎么回事阿,大家能看看我是那里出错了?
C程序我在很多地方找到的都不一样!这是怎么回事?
如:我在书上看到的:
#include<iostream>

int main()
{
std::cout<<"hello world!\n;
return 0;
}
wangxuyuan@wangxuyuan-laptop:~$ gcc -o hello.c vi.c

后面那个vi.c文件是干嘛的,应该把那个去掉就可以了吧。
poet
帖子: 2841
注册时间: 2006-09-11 22:47

#10

帖子 poet » 2008-04-12 13:26

最简单的 Makefile 写法:
假定你需要编译 hello.c

# Makefile 内容

all: hello

完了,就只需要一行代码,保存为 Makefile

然后可以在相同目录下使用 vi 里面的 make。

大多数情况下 Makefile 是比直接用 gcc 更方便的办法。

如果你编译的不是 hello.c 就把那个 hello 换成你需要的名字。
guhuipaul
帖子: 4
注册时间: 2008-09-10 1:41

编译c程序,说没有stdio.h 这个文件

#11

帖子 guhuipaul » 2008-09-17 22:20

终端输入vi hello.c

#include <stdio.h>
int main()
{
printf("hello man\n");
return 0;
}
退出,保存
再输入gcc hello.c
结果输出下面的东东

hello.c:1:19: 错误: stdio.h:没有该文件或目录
hello.c: 在函数‘main’中:
hello.c:4: 警告: 内建函数 ‘printf’ 不兼容的隐式声明

我确保自己的gcc是有装,而且是新的,请问各位大哥是什么原因
guhuipaul
帖子: 4
注册时间: 2008-09-10 1:41

#12

帖子 guhuipaul » 2008-09-17 22:25

找到答案了,抱歉,造成文字垃圾了
xeoc
帖子: 1994
注册时间: 2007-05-06 10:12

#13

帖子 xeoc » 2008-09-17 22:52

最佳解决办法看这里!把这个添加到vimrc里,按f5一切ok...

代码: 全选

" C的编译和运行
map <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec "w"
exec "!gcc % -o %<"
exec "! ./%<"
endfunc
回复