我还没有完成 C 驱动程序,但我正在使用 Qt Creator 完成 C++ 驱动程序。您需要在项目中包含 boost 库,并且——对于我下载的 MongoDB 客户端 C++ 版本——它们需要是 Boost 1.49 库,不多也不少。下载它并让它构建所有的库,即使你只需要其中的四个。以下是我的 Qt Creator .pro 文件中的相关代码,请注意我的 C:/MongoDB 文件夹中的所有内容都是从 MongoDB 源下载的,或者至少由 scons 从该直接下载中构建。
INCLUDEPATH += C:/MongoDB/src \
C:/MongoDB/src/mongo/client \
C:/MongoDB/src/third_party/boost \
C:/MongoDB/src/third_party/boost/boost \
C:/MongoDB/src/mongo \
C:/MongoDB/src/third_party/boost/boost/algorithm \
C:/MongoDB/src/third_party/boost/boost/asio \
C:/MongoDB/src/third_party/boost/boost/bind \
C:/MongoDB/src/third_party/boost/boost/concept \
C:/MongoDB/src/third_party/boost/boost/config \
C:/MongoDB/src/third_party/boost/boost/container \
C:/MongoDB/src/third_party/boost/boost/date_time \
C:/MongoDB/src/third_party/boost/boost/detail \
C:/MongoDB/src/third_party/boost/boost/exception \
C:/MongoDB/src/third_party/boost/boost/filesystem \
C:/MongoDB/src/third_party/boost/boost/function \
C:/MongoDB/src/third_party/boost/boost/functional \
C:/MongoDB/src/third_party/boost/boost/integer \
C:/MongoDB/src/third_party/boost/boost/io \
C:/MongoDB/src/third_party/boost/boost/iterator \
C:/MongoDB/src/third_party/boost/boost/math \
C:/MongoDB/src/third_party/boost/boost/move \
C:/MongoDB/src/third_party/boost/boost/mpl \
C:/MongoDB/src/third_party/boost/boost/numeric \
C:/MongoDB/src/third_party/boost/boost/optional \
C:/MongoDB/src/third_party/boost/boost/pending \
C:/MongoDB/src/third_party/boost/boost/preprocessor \
C:/MongoDB/src/third_party/boost/boost/program_options\
C:/MongoDB/src/third_party/boost/boost/random \
C:/MongoDB/src/third_party/boost/boost/range \
C:/MongoDB/src/third_party/boost/boost/regex \
C:/MongoDB/src/third_party/boost/boost/smart_ptr \
C:/MongoDB/src/third_party/boost/boost/spirit \
C:/MongoDB/src/third_party/boost/boost/system \
C:/MongoDB/src/third_party/boost/boost/test \
C:/MongoDB/src/third_party/boost/boost/thread \
C:/MongoDB/src/third_party/boost/boost/tuple \
C:/MongoDB/src/third_party/boost/boost/type_traits \
C:/MongoDB/src/third_party/boost/boost/typeof \
C:/MongoDB/src/third_party/boost/boost/units \
C:/MongoDB/src/third_party/boost/boost/unordered \
C:/MongoDB/src/third_party/boost/boost/utility \
DEFINES += _UNICODE \
SYM_STATICLIB
QMAKE_CFLAGS_RELEASE += /MT
QMAKE_CXXFLAGS_RELEASE += /MT
QMAKE_CFLAGS_DEBUG += /MTd
QMAKE_CXXFLAGS_DEBUG += /MTd
LIBS += -L$$PWD/../../../../../../MongoDB/src/third_party -lWS2_32
LIBS += -L$$PWD/../../../../../../MongoDB/src/third_party -lDbgHelp
CONFIG(debug, debug|release) {
LIBS += -LC:\MongoDB\build\win32\debug\client_build -lmongoclient
LIBS += -L$$PWD/../../../../../../Boost/1.49/bin.v2/libs/thread/build/msvc-10.0/debug/link-static/runtime-link-static/threading-multi/ -llibboost_thread-vc100-mt-sgd-1_49
LIBS += -L$$PWD/../../../../../../Boost/1.49/bin.v2/libs/date_time/build/msvc-10.0/debug/link-static/runtime-link-static/threading-multi/ -llibboost_date_time-vc100-mt-sgd-1_49
LIBS += -L$$PWD/../../../../../../Boost/1.49/bin.v2/libs/system/build/msvc-10.0/debug/link-static/runtime-link-static/ -llibboost_system-vc100-sgd-1_49
LIBS += -L$$PWD/../../../../../../Boost/1.49/bin.v2/libs/filesystem/build/msvc-10.0/debug/link-static/runtime-link-static/ -llibboost_filesystem-vc100-sgd-1_49
}
CONFIG(release, debug|release) {
LIBS += -LC:\MongoDB\build\win32\release\client_build -lmongoclient
LIBS += -L$$PWD/../../../../../../Boost/1.49/bin.v2/libs/thread/build/msvc-10.0/release/link-static/runtime-link-static/threading-multi/ -llibboost_thread-vc100-mt-s-1_49
LIBS += -L$$PWD/../../../../../../Boost/1.49/bin.v2/libs/date_time/build/msvc-10.0/release/link-static/runtime-link-static/threading-multi/ -llibboost_date_time-vc100-mt-s-1_49
LIBS += -L$$PWD/../../../../../../Boost/1.49/bin.v2/libs/system/build/msvc-10.0/release/link-static/runtime-link-static/ -llibboost_system-vc100-s-1_49
LIBS += -L$$PWD/../../../../../../Boost/1.49/bin.v2/libs/filesystem/build/msvc-10.0/release/link-static/runtime-link-static/ -llibboost_filesystem-vc100-s-1_49
}
请注意,已知 Qt 在针对静态 C++ 运行时构建时会出现异常行为,因此最好遵循我在此处给出的建议并将驱动程序包装在针对静态运行时构建的非 Qt C++ dll 中,然后在内部使用该 dll将针对动态运行时构建的主要 Qt 应用程序。
另请注意,我必须手动将 winsock 和帮助库复制到根文件夹中并手动包含它们,因为 Qt Creator 不接受“程序文件(x86)”路径,因为它有空格。
我意识到这不是“Mongo C”的答案,但你确实提到你只是出于挫败感而使用 C 驱动程序让 C++ 驱动程序工作,所以我想我会分享我所知道的。