举个例子
静态库的编译过程是
gcc -o a.o -c a.cpp
gcc -o b.o -c b.cpp
ar rcs liba.a *.o 」
假设b里面依赖了PB,但ar打包成liba.a过程中,完全没有去链接PB,没有和依赖的二级lib库有任何联编的地方。

所以如果另外一个程序要使用liba.a静态库,必须链接上PB库。

gcc -o b.o -c b.cpp ,b.cpp虽然用到了PB,但这个地方只是做符号的编译,没有做链接,也就不会编译报错。

静态库间接依赖 

要把a生成.o文件,然后做成.a静态库,但是a却依赖三方静态库 

//test.c, need pthread
#include <stdio.h>
#include <pthread.h>

int print(void)
{
    pthread_t tid;
    printf("test\n");
    pthread_create(&tid, NULL, NULL, NULL);

    return 0;
}

//main.c, need libts.a
#include <stdio.h>
 
extern int print(void);

int main()
{
    print();
      
    return 0;
}

gcc -c test.c
ar crv libts.a test.o

gcc main.c  -I./ -L./ -lts -lpthread

 

 

http://bbs.csdn.net/topics/391059666?page=1

讨论+请问:使用第三方开源库是否应该做二次封装

 

相关文章: