diff --git a/src/SConscript.client b/src/SConscript.client index 79e8857013..bc652098bc 100644 --- a/src/SConscript.client +++ b/src/SConscript.client @@ -378,14 +378,14 @@ if installSetup.headers or installSetup.libraries: include_bsonh_test, ]) -# Compile the example files to .o so that we can link them twice: once statically, once shared. -exampleObjMap = [(target, clientEnv.Object(source)) for (target, source) in exampleSourceMap] - staticClientEnv = clientEnv.Clone() staticClientEnv.PrependUnique(LIBDEPS=[mongoClientStaticLib]) +staticClientEnv.AppendUnique(CPPDEFINES=['STATIC_LIBMONGOCLIENT']) # Build each statically linked client program -staticClientPrograms = [staticClientEnv.Program(target, obj) for (target, obj) in exampleObjMap] +staticClientPrograms = [ + staticClientEnv.Program(target, source) for (target, source) in exampleSourceMap +] # Install them to the root, and append the install targets to the list of client tests clientTests = staticClientEnv.Install("#/", staticClientPrograms) @@ -402,6 +402,10 @@ if buildShared: LIBDEPS=mongoClientLibDeps, ) + # Pretend that these files are shared object suffixed so they don't conflict with the objects + # for the static library. + sharedClientEnv['OBJSUFFIX'] = sharedClientEnv['OBJSUFFIX'] + 's' + # Deal with the different lookup models between regular UNIX and Darwin. For regular unix, # we set $ORIGIN to pull the copy we run against from the current directory # (#/sharedclient). On Darwin, the staged copy of the mongoclient dylib in #sharedclient @@ -412,13 +416,14 @@ if buildShared: RPATH=[sharedClientEnv.Literal("\\$$ORIGIN")]) sharedClientPrograms = [ - sharedClientEnv.Program("sharedclient/" + target, obj) for (target, obj) in exampleObjMap] + sharedClientEnv.Program( + "sharedclient/" + target, source) for (target, source) in exampleSourceMap] libEnv.Depends(sharedClientPrograms, mongoClientInstalls) sharedClientProgramInstalls = sharedClientEnv.Install("#/sharedclient", sharedClientPrograms) clientTests.extend(sharedClientProgramInstalls) -clientEnv.Alias('clientTests', clientTests, []) +clientEnv.Alias('clientTests', clientTests) # NOTE: There must be a mongod listening on 127.0.0.1:27999 (the traditional mongodb smoke test # port) for the smokeClient target to run. In the server repo that is no problem, the smoke.py diff --git a/src/mongo/bson/bson.h b/src/mongo/bson/bson.h index 3ccbaec5a2..3fac500202 100644 --- a/src/mongo/bson/bson.h +++ b/src/mongo/bson/bson.h @@ -38,7 +38,13 @@ #error bson.h is for C++ driver consumer use only #endif +// Consumers of the MongoDB C++ client library must define STATIC_LIBMONGOCLIENT when including +// this header if they intend to link against the static version of the library. This is best +// handled by adding STATIC_LIBMONGOCLIENT to the list of definitions passed on each compile +// invocation. +#ifndef STATIC_LIBMONGOCLIENT #define LIBMONGOCLIENT_CONSUMER +#endif #include "mongo/client/redef_macros.h" diff --git a/src/mongo/client/dbclient.h b/src/mongo/client/dbclient.h index 9930688b81..1be7bbf3d5 100644 --- a/src/mongo/client/dbclient.h +++ b/src/mongo/client/dbclient.h @@ -25,7 +25,13 @@ #error dbclient.h is for C++ driver consumer use only #endif +// Consumers of the MongoDB C++ client library must define STATIC_LIBMONGOCLIENT when including +// this header if they intend to link against the static version of the library. This is best +// handled by adding STATIC_LIBMONGOCLIENT to the list of definitions passed on each compile +// invocation. +#ifndef STATIC_LIBMONGOCLIENT #define LIBMONGOCLIENT_CONSUMER +#endif #include "mongo/client/redef_macros.h"