- 论坛徽章:
- 0
|
本帖最后由 mickgrady 于 2011-03-05 16:31 编辑
程序1: hello.h
以下是代码片段:
#ifndef HELLO_H
#define HELLO_H
void hello(const char *name);
#endif //HELLO_H
程序2: hello.c
以下是代码片段:
#include
void hello(const char *name)
{
printf("Hello %s!\n", name);
}
程序3: test.c
以下是代码片段:
#include "hello.h"
int main()
{
hello("everyone" ;
return 0;
}
1.编译目标文件
gcc -c hello.c
2.创建静态库
ar cr libhello.a hello.o
3.拷贝到系统库文件夹
cp libhello.c /usr/include
4.期望这样执行可以成功
gcc -lhello test.c
可是结果
/tmp/ccZl8chZ.o: In function `main':
test.c .text+0x11): undefined reference to `hello'
collect2: ld returned 1 exit status
请问是我哪一步有问题??谢谢回答,不胜感激。 |
|