找不到main函数
- bones7456
- 帖子: 8495
- 注册时间: 2006-04-12 20:05
- 来自: 杭州
- 联系:
- caca
- 帖子: 22
- 注册时间: 2007-04-04 20:05
- 来自: dalian
我知道是什么错了,因为这个.c文件里没有main函数, 我直接执行gcc err.c当然不能生成可执行文件。不过我今天有出现了另一个问题。我编了一个hello.c
#include <stdio.h>
int main()
{
printf("hello\n");
return 0;
}
然后在同一目录下:vi makefile
hello: hello.o
gcc -o hello hello.o
hello.o:hello.c
gcc -c hello.c
clean:
rm hello.o
命令我用的是tap键
保存退出
执行make,产生 bash: make: command not found
我已经写了makefile了呀,怎么还会这样
#include <stdio.h>
int main()
{
printf("hello\n");
return 0;
}
然后在同一目录下:vi makefile
hello: hello.o
gcc -o hello hello.o
hello.o:hello.c
gcc -c hello.c
clean:
rm hello.o
命令我用的是tap键
保存退出
执行make,产生 bash: make: command not found
我已经写了makefile了呀,怎么还会这样
- xport
- 帖子: 1277
- 注册时间: 2006-05-19 21:23
- 联系:
有安装 make 么,一般来说安装了 build-essential 软件包比较方便,含了gcc和make等依赖的软件包。
查看 make 软件包安装状态 写了: $ aptitude show "make"
Package: make
State: installed
Automatically installed: no
Version: 3.81-3build1
Priority: optional
Section: devel
Maintainer: Ubuntu Core Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Uncompressed Size: 1237k
Depends: libc6 (>= 2.5-0ubuntu1)
Suggests: make-doc
Description: The GNU version of the "make" utility.
GNU Make is a program that determines which pieces of a large program need to be recompiled and issues the
commands to recompile them, when necessary. More information about GNU Make can be found in the `make' Info
page. The upstream sources for this package are available at the location ftp://ftp.gnu.org/gnu/make/. The
documentation for this package does not meet the Debian Free Software Guidelines, and has been removed from
this package.
其实我是一个演员!-http://blog.csdn.net/xport/
-
- 帖子: 353
- 注册时间: 2007-04-03 9:52
- 联系:
- bones7456
- 帖子: 8495
- 注册时间: 2006-04-12 20:05
- 来自: 杭州
- 联系:
- zhan
- 帖子: 1880
- 注册时间: 2005-08-15 0:04
- 来自: 南7技校
make 查找文件的顺序是 GNUmakefile Makefile 和 makefile.
大写只是一个风格的问题,同时,楼主的问题明显是编译环境的问题。没有 make . xport 说了办法了..
大写只是一个风格的问题,同时,楼主的问题明显是编译环境的问题。没有 make . xport 说了办法了..
飞得高,飞得低,学习再学习,多少大秘密!
http://zhan.blog.ubuntu.org.cn
http://zhan.blog.ubuntu.org.cn
- caca
- 帖子: 22
- 注册时间: 2007-04-04 20:05
- 来自: dalian
问题已经解决,确实是没安装make。谢谢!
首先谢谢前面为我解决问题的人,真心感谢,没想到这里回复的这么快。呵呵,以前的帖子好几天才看到有人回,可能是太弱智了吧。
不过,笨笨的我又碰到一个新问题,在写makefile时,包含头文件,执行make不错,找不到调用函数。
我的程序如下:
hello.c
#include<stdio.h>
#include "mysub.h"
int main()
{
printf("you are now in main process!\n");
func();
return 0;
}
mysub.h
void func();
sub.c
#include<stdio.h>
void func()
{
printf("you are now in sub process!\n");
}
makefile:
hello:hello.o
gcc -o hello hello.o
hello.o:hello.c mysub.h
gcc -c hello.c
hello.c. mysub.h.sub.c放在同一目录下
执行make,在main()函数里找不到func()的定义。
在终端执行gcc hello.c sub.c可以成功,还有,我把函数定义放在mysub.h中执行make可以通过
在包含自己定义的头文件时,makefile 应该怎么写呢?我这是照着老师的课件写的,昨天作实验也没有通过。
希望还有人看这个帖子,谢谢啊。
不过,笨笨的我又碰到一个新问题,在写makefile时,包含头文件,执行make不错,找不到调用函数。
我的程序如下:
hello.c
#include<stdio.h>
#include "mysub.h"
int main()
{
printf("you are now in main process!\n");
func();
return 0;
}
mysub.h
void func();
sub.c
#include<stdio.h>
void func()
{
printf("you are now in sub process!\n");
}
makefile:
hello:hello.o
gcc -o hello hello.o
hello.o:hello.c mysub.h
gcc -c hello.c
hello.c. mysub.h.sub.c放在同一目录下
执行make,在main()函数里找不到func()的定义。
在终端执行gcc hello.c sub.c可以成功,还有,我把函数定义放在mysub.h中执行make可以通过
在包含自己定义的头文件时,makefile 应该怎么写呢?我这是照着老师的课件写的,昨天作实验也没有通过。
希望还有人看这个帖子,谢谢啊。
上次由 caca 在 2007-06-19 17:13,总共编辑 1 次。
-
- 帖子: 353
- 注册时间: 2007-04-03 9:52
- 联系:
代码: 全选
all:hello
hello:hello.o sub.o
gcc -o hello hello.o sub.o
hello.o:hello.c
gcc -c hello.c
sub.o:sub.c
gcc -c sub.c
clean:
rm *.o hello
代码: 全选
#定议编译器和编译选项, 使用时用${ } 括起来
CC=gcc
CFLAGS=-g
all:hello
# $@ --目标文件
# $^ --所依赖的文件
hello:hello.o sub.o
${CC} ${CFLAGS} -o $@ $^
# .c .o --建立.c 到.o规则
# $< --第一个依赖文件
.c .o:
${CC} ${CFLAGS} $<
clean:
rm *.o hello