注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

勇敢的劳尤条

 
 
 

日志

 
 

CodeBlocks 链接库问题  

2014-06-13 15:35:01|  分类: 其他资料 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
编译codeBlocks程序,链接多线程库。链接到/usr/lib/x86_64-linux-gnu/libpthread.a
编译出现下面错误。

/usr/lib/x86_64-linux-gnu/libpthread.a(ptw-nanosleep.o)||In function `__nanosleep_nocancel':|
/build/buildd/eglibc-2.15/nptl/../sysdeps/unix/syscall-template.S|82|undefined reference to `__syscall_error'|
/build/buildd/eglibc-2.15/nptl/../sysdeps/unix/syscall-template.S|82|undefined reference to `__syscall_error'|
/usr/lib/x86_64-linux-gnu/libpthread.a(ptw-pause.o)||In function `__pause_nocancel':|
/build/buildd/eglibc-2.15/nptl/../sysdeps/unix/syscall-template.S|82|undefined reference to `__syscall_error'|
/build/buildd/eglibc-2.15/nptl/../sysdeps/unix/syscall-template.S|82|undefined reference to `__syscall_error'|
/usr/lib/x86_64-linux-gnu/libpthread.a(nptl-init.o)||In function `__pthread_initialize_minimal_internal':|
/build/buildd/eglibc-2.15/nptl/nptl-init.c|296|undefined reference to `__libc_setup_tls'|
/build/buildd/eglibc-2.15/nptl/nptl-init.c|314|undefined reference to `_dl_cpuclock_offset'|
/build/buildd/eglibc-2.15/nptl/nptl-init.c|430|undefined reference to `_dl_pagesize'|
/build/buildd/eglibc-2.15/nptl/nptl-init.c|456|undefined reference to `_dl_init_static_tls'|
/build/buildd/eglibc-2.15/nptl/nptl-init.c|458|undefined reference to `_dl_wait_lookup_done'|
/usr/lib/x86_64-linux-gnu/libpthread.a(nptl-init.o)||In function `__pthread_get_minstack':|
/build/buildd/eglibc-2.15/nptl/nptl-init.c|479|undefined reference to `_dl_pagesize'|
/usr/lib/x86_64-linux-gnu/libpthread.a(pthread_create.o)||In function `allocate_stack':|
/build/buildd/eglibc-2.15/nptl/allocatestack.c|457|undefined reference to `_dl_stack_flags'|
/build/buildd/eglibc-2.15/nptl/allocatestack.c|596|undefined reference to `_dl_stack_flags'|
||=== Build finished: 12 errors, 0 warnings ===|

对于g++ ,启用选项-lpthread,则没问题。
将链接改为/usr/lib/x86_64-linux-gnu/libpthread.so,则问题消失。不知道原因!

同样,编译另一个程序,用到mysql,链接到/usr/lib/x86_64-linux-gnu/libmysqlclient.a
编译出现如下错误。

/usr/lib/x86_64-linux-gnu/libmysqlclient.a(my_compress.c.o)||In function `my_uncompress':|
(.text+0x1f5)||undefined reference to `uncompress'|
/usr/lib/x86_64-linux-gnu/libmysqlclient.a(client_plugin.c.o)||In function `add_plugin':|
(.text+0x1ed)||undefined reference to `dlclose'|
/usr/lib/x86_64-linux-gnu/libmysqlclient.a(client_plugin.c.o)||In function `mysql_client_plugin_deinit':|
(.text+0x28b)||undefined reference to `dlclose'|
/usr/lib/x86_64-linux-gnu/libmysqlclient.a(client_plugin.c.o)||In function `mysql_load_plugin_v':|
(.text+0x51e)||undefined reference to `dlopen'|
/usr/lib/x86_64-linux-gnu/libmysqlclient.a(client_plugin.c.o)||In function `mysql_load_plugin_v':|
(.text+0x539)||undefined reference to `dlsym'|
/usr/lib/x86_64-linux-gnu/libmysqlclient.a(client_plugin.c.o)||In function `mysql_load_plugin_v':|
(.text+0x61a)||undefined reference to `dlerror'|
/usr/lib/x86_64-linux-gnu/libmysqlclient.a(client_plugin.c.o)||In function `mysql_load_plugin_v':|
(.text+0x62e)||undefined reference to `dlclose'|
||=== Build finished: 7 errors, 0 warnings ===|

对于g++ ,启用选项-lmysqlclient,则没问题。
将链接改为/usr/lib/x86_64-linux-gnu/libmysqlclient.so,,则问题消失。不知道原因!
**********************************************************************************************
我的猜测是,因为调用了PocoDataMySQL库,而它需要pthread库和mysqlclient库
而codeblocks并不能识别链接的先后顺序,所以它改成动态才行,需要dopen去找库的位置。
**********************************************************************************************


另外,用g++编译poco 数据库相关程序。

g++ main.cpp -o main -I/home/ys01/pocolib/include -I/usr/include/mysql -L/home/ys01/pocolib/lib -L/usr/local/lib -lPocoData -lmysqlclient -lPocoDataMySQL -lPocoFoundation

则出现下面问题。

/home/ys01/pocolib/lib/libPocoDataMySQL.a(Connector.o): In function `Poco::Data::MySQL::Connector::Connector()':
Connector.cpp:(.text+0xa5): undefined reference to `Poco::Data::Connector::Connector()'
/home/ys01/pocolib/lib/libPocoDataMySQL.a(Connector.o): In function `Poco::Data::MySQL::Connector::registerConnector()':
Connector.cpp:(.text+0xcc): undefined reference to `mysql_server_init'
/home/ys01/pocolib/lib/libPocoDataMySQL.a(Connector.o): In function `Poco::Data::MySQL::Connector::~Connector()':
Connector.cpp:(.text+0x6f): undefined reference to `Poco::Data::Connector::~Connector()'
/home/ys01/pocolib/lib/libPocoDataMySQL.a(Connector.o): In function `Poco::Data::MySQL::Connector::unregisterConnector()':
Connector.cpp:(.text+0x1cd): undefined reference to `mysql_server_end'
/home/ys01/pocolib/lib/libPocoDataMySQL.a(Connector.o):(.data.rel.ro._ZTIN4Poco4Data5MySQL9ConnectorE[typeinfo for Poco::Data::MySQL::Connector]+0x10): undefined reference to `typeinfo for Poco::Data::Connector'
......
Mutex.cpp:(.text+0x1e): undefined reference to `pthread_mutexattr_init'
Mutex.cpp:(.text+0x2d): undefined reference to `pthread_mutexattr_settype'
Mutex.cpp:(.text+0x48): undefined reference to `pthread_mutexattr_destroy'
Mutex.cpp:(.text+0x63): undefined reference to `pthread_mutexattr_destroy'
/home/ys01/pocolib/lib/libPocoFoundation.a(Mutex.o): In function `Poco::MutexImpl::MutexImpl(bool)':

......
Mutex.cpp:(.text+0x26b): undefined reference to `pthread_mutex_timedlock'

可以看出,我已经链接了mysqlclient,但是却说没有。PocoData也一样。

交换-l链接顺序,mysqlclient的错误就没有了。

g++ main.cpp -o main -I/home/ys01/pocolib/include -I/usr/include/mysql -L/home/ys01/pocolib/lib -L/usr/local/lib -lPocoData -lPocoDataMySQL -lmysqlclient  -lPocoFoundation

/home/ys01/pocolib/lib/libPocoDataMySQL.a(Connector.o): In function `Poco::Data::MySQL::Connector::Connector()':
Connector.cpp:(.text+0xa5): undefined reference to `Poco::Data::Connector::Connector()'
/home/ys01/pocolib/lib/libPocoDataMySQL.a(Connector.o): In function `Poco::Data::MySQL::Connector::~Connector()':
Connector.cpp:(.text+0x6f): undefined reference to `Poco::Data::Connector::~Connector()'
/home/ys01/pocolib/lib/libPocoDataMySQL.a(Connector.o):(.data.rel.ro._ZTIN4Poco4Data5MySQL9ConnectorE[typeinfo for Poco::Data::MySQL::Connector]+0x10): undefined reference to `typeinfo for Poco::Data::Connector'
/home/ys01/pocolib/lib/libPocoDataMySQL.a(SessionImpl.o): In function `Poco::Data::MySQL::SessionImpl::SessionImpl(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
SessionImpl.cpp:(.text+0x29a): undefined reference to `Poco::Data::SessionImpl::SessionImpl()'
/home/ys01/pocolib/lib/libPocoDataMySQL.a(SessionImpl.o): In function `Poco::Data::MySQL::SessionImpl::~SessionImpl()':
SessionImpl.cpp:(.text+0x225): undefined reference to `Poco::Data::SessionImpl::~SessionImpl()'
/home/ys01/pocolib/lib/libPocoDataMySQL.a(SessionImpl.o): In function `Poco::Data::AbstractSessionImpl<Poco::Data::MySQL::SessionImpl>::~AbstractSessionImpl()':
......
Extractor.cpp:(.text+0x40f): undefined reference to `Poco::Data::AbstractExtractor::~AbstractExtractor()'
/home/ys01/pocolib/lib/libPocoDataMySQL.a(Extractor.o):(.data.rel.ro._ZTIN4Poco4Data5MySQL9ExtractorE[typeinfo for Poco::Data::MySQL::Extractor]+0x10): undefined reference to `typeinfo for Poco::Data::AbstractExtractor'
collect2: ld returned 1 exit status


最后,这样编译成功了。

g++ main.cpp -o main -I/home/ys01/pocolib/include -I/usr/include/mysql -L/home/ys01/pocolib/lib -L/usr/local/lib -lPocoDataMySQL -lPocoData -lmysqlclient -lPocoFoundation

原因:因为链接库不是独立的,PocoDataMySQL依赖PocoData和mysqlclient,所以,他们必须排序。对于PocoDataMySQL里面的符号S的引用,在命令行选项中,至少要有S的定义出现在S的引用之后。所以,PocoDataMySQL之后一定要有PocoData和mysqlclient。
对于独立链接库,那么随意的顺序即可。

  评论这张
 
阅读(638)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017