gcc求助

编译打包和其他
回复
zxw
帖子: 7
注册时间: 2008-01-31 14:37

gcc求助

#1

帖子 zxw » 2008-02-01 14:27

我的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没配置好的缘故 请高位高手帮忙 谢了先
头像
bones7456
帖子: 8495
注册时间: 2006-04-12 20:05
来自: 杭州
联系:

#2

帖子 bones7456 » 2008-02-01 14:39

先把print.c 编译成print.o ,然后编译test.c的时候,使用print.o,最好写个makefile
关注我的blog: ε==3
zxw
帖子: 7
注册时间: 2008-01-31 14:37

#3

帖子 zxw » 2008-02-01 14:44

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
这样他以后也还是不行
zxw
帖子: 7
注册时间: 2008-01-31 14:37

#4

帖子 zxw » 2008-02-01 14:52

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
谢谢!
asran99
帖子: 1
注册时间: 2009-11-01 12:13

Re: gcc求助

#5

帖子 asran99 » 2009-11-07 17:56

请问可以把你的Makefile全部贴出来看下吗?我也遇到你以前遇到的问题,谢谢。
回复