利用mongodb c++ driver来编译 静态链接库, error LNK2001

利用mongodb c++ driver来编译 静态链接库,报错:
version.obj : error LNK2001: unresolved external symbol "void __cdecl boost::thr
ow_exception(class std::exception const &)" (?throw_exception@boost@@YAXABVexcep
tion@std@@@Z)

解决方法是修改SConstruct:
添加 env.AppendUnique(CXXFLAGS=Split("/EHsc"));
这个选项为编译动态链接库,应该去掉


以下为修改后的SConstruct,仅供参考
[quote]
# 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",
help="installation root" )


AddOption( "--release", dest="release", type="string", nargs=0, action="store", help="release build" )

env = Environment( MSVS_ARCH=None )
debug = False

def has_option( name ):
x = GetOption( name )
if x is None:
return False

return True

release = has_option( "release" )

if release:
print("release")
debug = False
else:
print("debug")
debug = True

def addExtraLibs( s ):
for x in s.split(","):
if os.path.exists( x ):
env.Append( CPPPATH=[ x + "/include" ] )
env.Append( LIBPATH=[ x + "/lib" ] )
env.Append( LIBPATH=[ x + "/lib64" ] )


#add boost
boostDir = "E:/boost"
env.Append( CPPPATH=[ boostDir ] )
env.Append( LIBPATH=[ boostDir + "/lib" ] )

#add pcre
env.Append( CPPPATH=[ "./third_party/pcre-7.4" ] )
env.Append( LIBPATH=[ "./"] )

#set unicode
env.Append( CPPDEFINES=[ "_UNICODE" ] )
env.Append( CPPDEFINES=[ "UNICODE" ] )


#env.Append( CPPFLAGS="Ehsc" )
env.AppendUnique(CXXFLAGS=Split("/EHsc"));

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" )
env.Append( LIBS=["pthread"] )
if linux:
env.Append( LINKFLAGS=" -Wl,--as-needed -Wl,-zdefs " )

#add libs: thread, filesystem, program_options
boostLibs = [ "thread" , "filesystem", "program_options" ]

#for lib in boostLibs:
#env.Append( LIBS=[ "boost_%s-vc100-mt-1_48" % lib] )
#print("boost_%s-vc100-mt-1_48" % lib)

conf = Configure(env)
if debug:
env.Append( CPPDEFINES=[ "_DEBUG" ] )
env.Append( CPPFLAGS=" /MTd " )
for lib in boostLibs:
if not conf.CheckLib("boost_%s-vc100-mt-gd-1_48" % lib):
conf.CheckLib("boost_%s-mt-1_48" % lib)
else:
env.Append( CPPDEFINES=[ "NDEBUG" ] )
env.Append( CPPFLAGS=" /MT " )
for lib in boostLibs:
if not conf.CheckLib("boost_%s-vc100-mt-1_48" % lib):
conf.CheckLib("boost_%s-mt-1_48" % 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 + "/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, [])


[/quote]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值