问题描述:
链接库:libsnlp_client.a 时提示大量未定义符号或引用:
/home/work/wlh01/searchsuggest/git-suggest/suggest/scf/snlp_client/snlpservice_TokenizerService_ClientInterface.cpp:22: undefined reference to `scf::ProxyStandard::ProxyStandard(std::string, char*, bool)'
/home/work/wlh01/searchsuggest/git-suggest/suggest/scf/snlp_client/snlpservice_TokenizerService_ClientInterface.cpp:26: undefined reference to `scf::Parameter::Parameter(int, char*, void*, bool, ParaType)'
/home/work/wlh01/searchsuggest/git-suggest/suggest/scf/snlp_client/snlpservice_TokenizerService_ClientInterface.cpp:29: undefined reference to `scf::Parameter::Parameter(int, char*, void*, bool, ParaType)'
/home/work/wlh01/searchsuggest/git-suggest/suggest/scf/snlp_client/snlpservice_TokenizerService_ClientInterface.cpp:32: undefined reference to `null_aic'
/home/work/wlh01/searchsuggest/git-suggest/suggest/scf/snlp_client/snlpservice_TokenizerService_ClientInterface.cpp:32: undefined reference to `scf::ProxyStandard::invoke(char*, scf::Parameter**, int, int*, AsynInvokeContext&)'
/home/work/wlh01/searchsuggest/git-suggest/suggest/scf/snlp_client/snlpservice_TokenizerService_ClientInterface.cpp:35: undefined reference to `scf_free'
...
../../lib/libsnlp_client.a(TokenizerService_Common_ClientInterface.o): In function `registerAll()':
/home/work/wlh01/searchsuggest/git-suggest/suggest/scf/snlp_client/./TokenizerService_Common_ScfEntity.h:9: undefined reference to `INFO_REGISTRED'
collect2: error: ld returned 1 exit status
make: *** [snlp_demo] 错误 1
问题分析:
make的链接选项为:
g++ -o ../bin/demo demo.o -Wl,-dn -lclient -lprotocol -lserialize -ljsonparser -lutils -lthreadpool -ltinyxpath -lsnlp_client -Wl,-dy -llog4cxx -lpthread -lz -lpcre -lboost_system
snlp_client.a依赖libprotocol.a和libclient.a,但是libsnlp_client.a在这两个库之后,先链接libprotocol.a和libclient.a时,snlp_client.a需要的符号不会被链接进来(链接静态库时的默认配置,以减小最终程序的大小)。等到链接snlp_client.a时,就会出现找不到snlp_client.a需要的符号问题了。
解决办法:
- 将 -lsnlp_client 的位置挪到 -lclient 之前。
在尝试链接静态库libsnlp_client.a时遇到大量未定义符号错误。问题源于链接顺序:libsnlp_client.a在libprotocol.a和libclient.a之后。解决方法是调整链接选项,将-lsnlp_client移到-lclient之前,确保依赖的符号在链接时得以解决,从而避免程序大小不必要的增加。

1万+

被折叠的 条评论
为什么被折叠?



