mongoDBはpythonを使うのが一番いいのかも知れませぬ。書籍もあるますし。
C++のドライバがありますが、boostと絡むので、時間がかかりました。(3時間程度) ι(´Д`υ)
[root@localhost mongo-cxx-driver-v2.0]# uname -a
Linux localhost.localdomain 2.6.33.3-85.fc13.x86_64 #1 SMP Thu May 6 18:09:49 UTC 2010 x86_64 x86_64 x86_64 GNU/Linux
wget http://downloads.mongodb.org/cxx-driver/mongodb-linux-x86_64-v2.0-latest.tgz
まずは、yumかsource codeでboostをインストールする。そして、
scons: Reading SConscript files ...
Checking for C library boost_thread-mt... no
Checking for C library boost_thread... no
Checking for C library boost_filesystem-mt... no
Checking for C library boost_filesystem... no
Checking for C library boost_system-mt... (cached) no
Checking for C library boost_system... no
Checking for C library boost_thread-mt... (cached) no
Checking for C library boost_thread... no
scons: done reading SConscript files.
ではなく、
[root@localhost mongo-cxx-driver-v2.0]# scons
scons: Reading SConscript files ...
Checking for C library boost_thread-mt... (cached) yes
Checking for C library boost_filesystem-mt... (cached) yes
Checking for C library boost_system-mt... (cached) yes
Checking for C library boost_thread-mt... (cached) yes
scons: done reading SConscript files.
scons: Building targets ...
g++ -o mongo/buildinfo.os -c -fPIC -O3 -lboost_system -D_SCONS -DMONGO_EXPOSE_MACROS -Imongo mongo/buildinfo.cpp
g++ -o mongo/pch.os -c -fPIC -O3 -lboost_system -D_SCONS -DMONGO_EXPOSE_MACROS -Imongo mongo/pch.cpp
となるまでがんばってくだしゃれ。
その後、Sconstructを修正しました。
ranlib libmongoclient.a
g++ -o authTest -Wl,--as-needed -Wl,-zdefs client/examples/authTest.o -L. -lmongoclient -lpthread -lboost_thread-mt -lboost_filesystem-mt -lboost_system-mt -lboost_thread-mt
client/examples/authTest.o: In function `global constructors keyed to main':
g++ -o mongo/pch.o -c -O3 -lboost_system -D_SCONS -DMONGO_EXPOSE_MACROS -I/usr/local/boost/include -Imongo mongo/pch.cpp
g++ -o libmongoclient.so -Wl,--as-needed -Wl,-zdefs -Wl,-lboost_system -shared mongo/buildinfo.os mongo/pch.os mongo/bson/oid.os mongo/client/clientOnly.os mongo/client/connpool.os mongo/client/dbclient.os mongo/client/dbclient_rs.os mongo/client/dbclientcursor.os mongo/client/distlock.os mongo/client/gridfs.os mongo/client/model.os mongo/client/syncclusterconnection.os mongo/s/shardconnection.os mongo/shell/mongo.os mongo/db/commands.os mongo/db/indexkey.os mongo/db/jsobj.os mongo/db/json.os mongo/db/lasterror.os mongo/db/nonce.os mongo/db/projection.os mongo/db/querypattern.os mongo/db/queryutil.os mongo/util/assert_util.os mongo/util/background.os mongo/util/base64.os mongo/util/debug_util.os mongo/util/file_allocator.os mongo/util/histogram.os mongo/util/log.os mongo/util/md5main.os mongo/util/password.os mongo/util/ramlog.os mongo/util/signal_handlers.os mongo/util/stringutils.os mongo/util/text.os mongo/util/util.os mongo/util/version.os mongo/util/concurrency/spin_lock.os mongo/util/concurrency/synchronization.os mongo/util/concurrency/task.os mongo/util/concurrency/thread_pool.os mongo/util/concurrency/vars.os mongo/util/net/httpclient.os mongo/util/net/listen.os mongo/util/net/message.os mongo/util/net/message_port.os mongo/util/net/sock.os mongo/util/md5.os -L/usr/local/lib -L/usr/local/lib64 -lpthread -lboost_thread-mt -lboost_filesystem-mt -lboost_system-mt -lboost_thread-mt
mongo/buildinfo.os: In function `global constructors keyed to buildinfo.cpp':
buildinfo.cpp:(.text+0x3b): undefined reference to `boost::system::generic_category()'
というエラーが100回ほどでたので、(;´Д`)SConstructを修正した(mtの文字を削除)
conf = Configure(env)
for lib in boostLibs:
if not conf.CheckLib("boost_%s" % lib):
conf.CheckLib("boost_%s" % lib)
mongodb-develとかをyumでいれませぅ。
cp ./libmongoclient.so /usr/local/lib
ldconfig /usr/local/lib
[root@localhost ~]# g++ -g -Wall -I/usr/include -L/usr/local/libs -lmongoclient -lboost_system mongo_test.cpp -o m
ongo_test
とにかくエラーがでるとライブラリが作成されません。下記は一応うまくいったSConstructです。
# scons file for MongoDB c++ client library and examples
import os
# options
AddOption( "--extrapath",
dest="extrapath",
type="string",
nargs=1,
action="store",
help="comma separated list of add'l paths (--extrapath /opt/foo/,/foo) static linking" )
AddOption( "--prefix",
dest="prefix",
type="string",
nargs=1,
action="store",
default="/usr/local/boost",
help="installation root" )
env = Environment( MSVS_ARCH=None )
def addExtraLibs( s ):
for x in s.split(","):
if os.path.exists( x ):
env.Append( CPPPATH=[ x + "/include/boost" ] )
env.Append( LIBPATH=[ x + "/lib" ] )
env.Append( LIBPATH=[ x + "/lib64" ] )
if GetOption( "extrapath" ) is not None:
addExtraLibs( GetOption( "extrapath" ) )
env.Append( CPPPATH=[ "mongo/" ] )
env.Append( CPPDEFINES=[ "_SCONS" , "MONGO_EXPOSE_MACROS" ] )
nix = False
linux = False
if "darwin" == os.sys.platform:
addExtraLibs( "/opt/local/" )
nix = True
elif "linux2" == os.sys.platform or "linux3" == os.sys.platform:
nix = True
linux = True
if nix:
env.Append( CPPFLAGS=" -O3 -lboost_system" )
env.Append( LIBS=["pthread"] )
env.Append( LDFLAGS=" -lboost_system" )
if linux:
env.Append( LINKFLAGS=" -Wl,--as-needed -Wl,-zdefs -Wl,-lboost_system" )
env.Append( LDFLAGS=" -lboost_system" )
boostLibs = [ "thread" , "filesystem" , "system", "thread" ]
conf = Configure(env)
for lib in boostLibs:
if not conf.CheckLib("boost_%s" % lib):
conf.CheckLib("boost_%s" % lib)
dirs = [ "" , "bson/" , "bson/util/" ,
"client/" , "s/" , "shell/" ,
"db/" ,
"scripting/" ,
"util/" , "util/concurrency/" , "util/mongoutils/" , "util/net/" ]
allClientFiles = []
for x in dirs:
allClientFiles += Glob( "mongo/" + x + "*.cpp" )
allClientFiles += Glob( "mongo/util/*.c" )
libs = []
libs += env.SharedLibrary( "mongoclient" , allClientFiles )
libs += env.Library( "mongoclient" , allClientFiles )
# install
prefix = GetOption( "prefix" )
for x in libs:
env.Install( prefix + "/lib/" , str(x) )
for x in dirs:
x = "mongo/" + x
env.Install( prefix + "/boost/include/" + x , Glob( x + "*.h" ) )
env.Alias( "install" , prefix )
# example setup
#clientTests = []
#clientEnv = env.Clone();
#clientEnv.Prepend( LIBS=["libmongoclient.a"])
#clientEnv.Prepend( LIBPATH=["."] )
# examples
#clientTests += [ clientEnv.Program( "firstExample" , [ "client/examples/first.cpp" ] ) ]
#clientTests += [ clientEnv.Program( "secondExample" , [ "client/examples/second.cpp" ] ) ]
#clientTests += [ clientEnv.Program( "whereExample" , [ "client/examples/whereExample.cpp" ] ) ]
#clientTests += [ clientEnv.Program( "authTest" , [ "client/examples/authTest.cpp" ] ) ]
#clientTests += [ clientEnv.Program( "httpClientTest" , [ "client/examples/httpClientTest.cpp" ] ) ]
#clientTests += [ clientEnv.Program( "clientTest" , [ "client/examples/clientTest.cpp" ] ) ]
#clientEnv.Alias("clientTests", clientTests, [])
最近のコメント