分页: 1 / 1

gcc求助

发表于 : 2008-02-01 14:27
zxw
我的gcc编译单个文件的时候没问题 但就是找不到自定义头文件里函数 几个文件是这样子的
test.c:
#include "print.h"
int main()
{
print("hello world\n!");
return 0;
}

print.h:
#ifndef _PRINT_H
#define _PRINT_H
void print(char *str1);
#endif

print.c:
#include "print.h"
#include <stdio.h>
void print(char *str1)
{
printf("%s",str1);
}

然后 gcc -o test test.c
提示是:
/tmp/cckKFlSB.o: In function `main':
test.c:(.text+0x19): undefined reference to `print'
collect2: ld 返回 1
不知道是不是gcc没配置好的缘故 请高位高手帮忙 谢了先

发表于 : 2008-02-01 14:39
bones7456
先把print.c 编译成print.o ,然后编译test.c的时候,使用print.o,最好写个makefile

发表于 : 2008-02-01 14:44
zxw
bones7456 写了:先把print.c 编译成print.o ,然后编译test.c的时候,使用print.o,最好写个makefile
我是写了makefile了的
test:test.o
gcc -o test test.o
test.o:test.c print.h
gcc -c test.c
这样他以后也还是不行

发表于 : 2008-02-01 14:52
zxw
bones7456 写了:先把print.c 编译成print.o ,然后编译test.c的时候,使用print.o,最好写个makefile
好了搞定了
我把makefile改成
test:test.o print.o
test.o:test.c print.h
print.o:print.c
谢谢!

Re: gcc求助

发表于 : 2009-11-07 17:56
asran99
请问可以把你的Makefile全部贴出来看下吗?我也遇到你以前遇到的问题,谢谢。