分页: 1 / 3
我的c程序怎么老是弄不出来阿
发表于 : 2008-03-10 20:17
由 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;
}
发表于 : 2008-03-10 20:31
由 urmysweety
gcc -o aaa hello.c
这样看看
其中aaa是自己定义生成的可执行文件的名称
发表于 : 2008-03-10 20:34
由 w3484732
wangxuyuan@wangxuyuan-laptop:~$ gcc -o aaa hello.c
hello.c:1:19: 错误: stdio.h:No such file or directory
hello.c: 在函数 ‘main’ 中:
hello.c:5: 警告: 隐式声明与内建函数 ‘printf’ 不兼容
wangxuyuan@wangxuyuan-laptop:~$
不行!是不是我写的程序有问题?
发表于 : 2008-03-10 20:44
由 urmysweety
你安装了库没有?
发表于 : 2008-03-10 20:47
由 dbzhang800
w3484732 写了:wangxuyuan@wangxuyuan-laptop:~$ gcc -o aaa hello.c
hello.c:1:19: 错误: stdio.h:No such file or directory
hello.c: 在函数 ‘main’ 中:
hello.c:5: 警告: 隐式声明与内建函数 ‘printf’ 不兼容
wangxuyuan@wangxuyuan-laptop:~$
不行!是不是我写的程序有问题?
代码: 全选
sudo apt-get install build-essential
先装好编译环境。
发表于 : 2008-03-10 21:03
由 w3484732
哦!那我先去装!
现在出现了个问题!
我退出VIM后再使用:vim hello.c打开我编译的文件时出现:
E325: ATTENTION
Found a swap file by the name ".hello.c.swp"
owned by: wangxuyuan dated: Mon Mar 10 20:54:54 2008
file name: ~wangxuyuan/hello.c
modified: YES
user name: wangxuyuan host name: wangxuyuan-laptop
process ID: 10175
While opening file "hello.c"
dated: Mon Mar 10 20:12:36 2008
(1) Another program may be editing the same file.
If this is the case, be careful not to end up with two
different instances of the same file when making changes.
Quit, or continue with caution.
(2) An edit session for this file crashed.
If this is the case, use ":recover" or "vim -r hello.c"
to recover the changes (see ":help recovery").
If you did this already, delete the swap file ".hello.c.swp"
to avoid this message.
"hello.c" 7L, 74C
Press ENTER or type command to continue
完后点个回车就好了,这是怎么回事?
发表于 : 2008-03-10 21:24
由 dbzhang800
两个可能原因你自己都贴出来了。
1 你用vim打开文件时,可能有一个vim已经打开了该文件
2 你上次用vim编辑该文件时vim崩溃了,比如 直接关掉终端,直接关机等导致vim被强制关掉
,
发表于 : 2008-03-10 21:36
由 w3484732
哦是这样的阿!谢谢受教了!
我现在按上面说的完成了HELLO WORLD的编译.但是生成的aaa程序不能运行,双击没有反应!
这是怎么回事?在终端里可以运行!
wangxuyuan@wangxuyuan-laptop:~$ ./aaa
Hello, world!
wangxuyuan@wangxuyuan-laptop:~$
这个没有问题!但是在图文界面上就不行了
[img]file:///home/wangxuyuan/Desktop/Screenshot.png[/img]
这是怎么回事阿?
发表于 : 2008-03-10 21:49
由 Yizer
w3484732 写了:哦是这样的阿!谢谢受教了!
我现在按上面说的完成了HELLO WORLD的编译.但是生成的aaa程序不能运行,双击没有反应!
这是怎么回事?在终端里可以运行!
wangxuyuan@wangxuyuan-laptop:~$ ./aaa
Hello, world!
wangxuyuan@wangxuyuan-laptop:~$
这个没有问题!但是在图文界面上就不行了
[img]file:///home/wangxuyuan/Desktop/Screenshot.png[/img]
这是怎么回事阿?
你双击时已经运行了。。。。只是太快了一闪而过而已。。。。
发表于 : 2008-03-10 21:56
由 w3484732
晕有什么办法让他慢点么?给他加个什么命令?
发表于 : 2008-03-10 22:09
由 zhihuasz
w3484732 写了:晕有什么办法让他慢点么?给他加个什么命令?
scanf()
发表于 : 2008-03-12 18:05
由 w3484732
现在又来了个问题:
我把编译好的程序做了改动,用GCC就编译不了了,怎么回事阿?
实际情况:
编译后能运行的:
#include <stdio.h>
int main()
{
printf("Hello, wo1111111111111111111111rld!\n");
return 0;
}
再改动后的:
#include <stdio.h>
int main()
{
printf("Hello, w1orld!\n");
return 0;
}
使用GCC命令:
第一个:
wangxuyuan@wangxuyuan-laptop:~$ gcc -o wang hello.c
wangxuyuan@wangxuyuan-laptop:~$
第二个:
123: file not recognized: File format not recognized
collect2: ld 返回 1
wangxuyuan@wangxuyuan-laptop:~$
第二个告诉我说: 文件形式不承认。这是怎么回事阿?
发表于 : 2008-03-12 18:34
由 BigSnake.NET
rm 掉之前的文件
发表于 : 2008-03-12 18:49
由 w3484732
把什么都RM后又出现了:
发表于 : 2008-03-12 19:09
由 BigSnake.NET
你怎么不看输出信息呢, 没有输入文件