利用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,仅供参考
引用
# 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:
&