当前位置:数据库 > mongodb >>

c++程序在Ubuntu 13.10上链接mongodb报错

在最新的Ubuntu13.10上,用编译器clang3.4编译我原来的程序,出现错误:
[plain] 
c++ -g .private/windtunnel/code/site/builder/object/site_response.cc.o .private/windtunnel/code/site/builder/object/my_app.cc.o .private/windtunnel/code/site/builder/object/mongo_session.cc.o .private/windtunnel/code/site/builder/object/time_helper.cpp.o .private/windtunnel/code/site/builder/object/data.cc.o .private/windtunnel/code/site/builder/object/main.cpp.o .private/windtunnel/code/site/builder/object/mems.cc.o .private/windtunnel/code/site/builder/object/data_service.cc.o .private/windtunnel/code/site/builder/object/host.cc.o .private/windtunnel/code/site/builder/object/cpus.cc.o .private/windtunnel/code/site/builder/object/mongo_session_factory.cc.o .private/windtunnel/code/site/builder/object/hosts.cc.o .private/windtunnel/code/site/builder/object/site.cc.o .private/windtunnel/code/site/builder/object/host_service.cc.o .private/windtunnel/code/site/builder/object/home.cc.o -o bin/wind_tunnel -rdynamic -lpthread -lcppcms -lmongoclient -lbooster -lcryptopp -lboost_system -lboost_thread -lboost_filesystem  
/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/libmongoclient.a(spin_lock.o): undefined reference to symbol 'pthread_yield@@GLIBC_2.2.5'  
/lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line  
collect2: error: ld returned 1 exit status  
 
其实只要把-lpthread换成-pthread就好了。
 
问题就是-lpthread和-pthread区别是什么? 参考话题:
http://stackoverflow.com/questions/875789/gcc-do-i-need-d-reentrant-with-pthreads/876005#876005
https://groups.google.com/forum/#!topic/comp.programming.threads/NCEpG0EOCCY
 
-pthread就是 -D_REENTRANT -lpthread
[plain]  
`-pthread'  
     Adds support for multithreading with the "pthreads" library.  This  
     option sets flags for both the preprocessor and linker.  
 
补充:软件开发 , C++ ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,