|
|

楼主 |
发表于 2005-12-15 11:41:39
|
显示全部楼层
我写了一段小程序作为例子
***********************
[root@localhost ar]# gcc -c hellofirst.c hellosecond.c hellos.c
[root@localhost ar]# ar -r libhello.a hellofirst.o hellosecond.o
ar: 正在创建 libhello.a
[root@localhost ar]# ar -r libhellos.a hellos.o libhello.a
ar: 正在创建 libhellos.a
[root@localhost ar]# gcc ovxt.c libhellos.a -o ovxt
libhellos.a(hellos.o)(.text+0x7): In function `hello':
: undefined reference to `hellofirst'
libhellos.a(hellos.o)(.text+0xc): In function `hello':
: undefined reference to `hellosecond'
collect2: ld returned 1 exit status
[root@localhost ar]#
/*hellofirst.c*/
#include <stdio.h>
extern void hellofirst();
void hellofirst()
{
printf("The first hello\n");
}
/*hellosecond.c*/
#include <stdio.h>
extern void hellosecond();
void hellosecond()
{
printf("The second hello\n");
}
/*hellos.c*/
extern void hellofirst();
extern void hellosecond();
extern void hello(void)
{
hellofirst();
hellosecond();
}
/*ovxt.c*/
extern void hello(void);
int main(int argc, char *argv[])
{
hello();
return(0);
}
************************ |
|