LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 763|回复: 4

可以用一行那样统一编译成功为什么分开就不行了呢?

[复制链接]
发表于 2004-5-16 11:24:43 | 显示全部楼层 |阅读模式
这个程序是制顶帖中的那个演示怎么使用make的程序。
写好后,我可以用
gcc -o main.c func1.c func2.c编译成功,但是我要是分开编译就不行了
[bisong@localhost progtest]$ gcc -c main.c
[bisong@localhost progtest]$ gcc -c func1.c
[bisong@localhost progtest]$ gcc -c func2.c
[bisong@localhost progtest]$ gcc -o main.o func1.o func2.o
/usr/lib/gcc-lib/i386-redhat-linux/3.2.2/../../../crt1.o(.text+0x18): In function `_start':../sysdeps/i386/elf/start.S:77: undefined reference to `main'
collect2: ld returned 1 exit status
不知道这是为什么
我按照那个置顶帖上的Makefile抄了一下,但是在我make的时候出现下面的错误
[bisong@localhost progtest]$ make
Makefile:2: *** missing separator.  Stop.
这个是什么意思阿?
小弟刚接触linux的编成,望各位大哥大姐多多帮助。
#include<stdio.h>
#include "mytool1.h"
#include "mytool2.h"

int main()
{
     printf("Now In main function\n");
     func1("Now In func1\n");
     func2("Now In func2\n");
      
     return 0;
}
[bisong@localhost progtest]$ cat func1.c
#include "mytool1.h"

void func1(char *print_str)
{
     printf("This is func1 print %s\n", print_str);
}
[bisong@localhost progtest]$ cat func2.c
#include "mytool2.h"

void func2(char *print_str)
{
     printf("This is func2 print %s\n",print_str);
}
[bisong@localhost progtest]$ cat mytool1.h
#ifndef _MYTOOL_1_H
#define _MYTOOL_1_H

void func1(char *print_str);

#endif
[bisong@localhost progtest]$ cat mytool2.h
#ifndef _MYTOOL_2_H
#define _MYTOOL_2_H

void func2(char *print_str);

#endif
 楼主| 发表于 2004-5-16 22:45:45 | 显示全部楼层
为什么没人理我呢?
发表于 2004-5-16 23:55:49 | 显示全部楼层
你的makefile有问题,把他贴出来!
发表于 2004-5-17 00:22:12 | 显示全部楼层
gcc的-o选项要根输出目标,
如:-o xx 将生成xx程序代替默认的a.out,你用:
gcc -c main.c
gcc -c func1.c
gcc -c func2.c
gcc main.o func1.o func2.o -o xx
就不会有问题
 楼主| 发表于 2004-5-20 18:12:06 | 显示全部楼层
谢谢大家,我的makefile是有问题。现在好了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表