在链接时库的顺序问题

今天用GNU autotools编译原来的程序时,碰到一大堆undefined reference的链接错误。

/home/wensong/devel/dragon/services/ExpireRegistrations.hxx:14: undefined
 reference to `CThreadIf::CThreadIf()'
../services/libservices.a(StunService.o)(.text+0x12): In function
 `StunService::StunService(Service const&)':
/home/wensong/devel/dragon/services/StunService.cxx:17: undefined reference to
 `CThreadIf::CThreadIf(int)'
../services/libservices.a(StunService.o)(.text+0x3b):/home/wensong/devel/dragon
/services/StunService.cxx:17: undefined reference to `vtable for CThreadIf'
../services/libservices.a(StunService.o)(.text+0x62): In function
 `StunService::StunService(Service const&)':
/home/wensong/devel/dragon/services/StunService.cxx:17: undefined reference
 to `CThreadIf::CThreadIf(int)'
../services/libservices.a(StunService.o)(.text+0x8b):/home/wensong/devel/dragon
/services/StunService.cxx:17: undefined reference to `vtable for CThreadIf'
../services/libservices.a(StunService.o)(.text+0xcb): In function
 `StunService::~StunService()':
...

但CThreadIf的实现明明是有的,后来才发现在链接时库文件有先后顺序问题。

假设我们有程序a依赖有库b和c,其中库c依赖库b,则在链接时库c应该写在库b的前面。在automake文件中写:

a_LDADD = libc.a libb.a

randomness