makefile求指导
c语言吧
全部回复
仅看楼主
level 3
makefile如下:
hello : hello.c a.c
gcc -o hello hello.c fun.c
hello.o : hello.c
gcc -o hello.o -c hello.c
a.o : a.c
gcc -o a.o -c a.c
hello.c如下:
# include <stdio.h>
# include "a.c"
extern void fun(void);
int main(void)
{
printf("Hello World!\n");
fun();
}
a.c如下:
void fun(void)
{
printf("Hello ARM!\n");
}
然后make,提示fun函数多次定义(multiple definition of 'fun')
,注释掉# include "a.c",就好了,直接gcc -o hello hello.c a.c没问题,求大神指导,为什么啊
2014年04月29日 10点04分 1
level 12
都什么乱七八糟的。。。
2014年04月29日 11点04分 2
跟Makefile有什么关系, [滑稽]
2014年04月29日 11点04分
level 6
楼主再仔细学一下makefile和gcc吧
2014年04月29日 12点04分 3
level 8
Makefile写错了.
2014年04月29日 13点04分 4
gcc -o hello hello.c fun.c写成gcc -o hello hello.c a.c了,其它还有问题么,暂不考虑# include "a.c",大神
2014年04月29日 23点04分
回复 彭华林smile :你把a.c都 include到hello.c里面了,就相当于a.c的内容,是hello.c里面的内容.所以要么该Makefile,要么该#include "a.c".
2014年04月30日 02点04分
level 13
include.c[不高兴][疑问]
2014年04月29日 14点04分 5
level 11
你百度下为什么不用include .c文件
2014年04月29日 23点04分 8
level 13
这与Makefile有什么关系?问题就出在#include "a.c",你加了这个,那hello.c就包含了a.c的内容,你再来个a.c,那就重复了。
2014年04月29日 23点04分 9
level 14
lz
,首先你要明白#inlcude 是在预编译的时候处理的,
然后,你用gcc 生成预编译后的文件,你就知道问题出 哪了,
好好看书,打好基础
2014年04月30日 04点04分 19
level 12
虽说makefile写错了 但问题不在这里
2014年04月30日 06点04分 20
1