Details
-
Bug
-
Resolution: Done
-
Trivial - P5
-
None
-
3.1.3
-
None
-
None
-
Operating System: macOS Sierra 10.12.6
IDE: CLion 2017.2.2 Build #CL-172.3968.17, built on August 22, 2017
CMake: 3.8.2
mongo-cxx-driver: 3.1.3
mongo-c-driver: 1.8.0
Description
I am currently developing a C++ application which requires the use of the mongo-cxx-driver for accessing a MongoDB instance. I attempted a couple of methods of installation, and am met with the same linker issues each time.
Initially, I attempted to install mongo-cxx-drivers and mongod-c-driver as detailed here: https://mongodb.github.io/mongo-cxx-driver/mongocxx-v3/installation/
Using the following portion of my CMake configuration, I was able to get auto-completion working and my IDE to recognize the libraries:
. . .
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
|
set(BUILD_DIR "cmake-build-debug")
|
set(BUILD_PATH "${CMAKE_SOURCE_DIR}/${BUILD_DIR}")
|
|
|
find_package(libmongocxx REQUIRED)
|
find_package(libbsoncxx REQUIRED)
|
|
|
message("LIBMONGOCXX_INCLUDE_DIRS = ${LIBMONGOCXX_INCLUDE_DIRS}")
|
message("LIBMONGOCXX_LIBRARIES = ${LIBMONGOCXX_LIBRARIES}")
|
|
|
message("LIBBSONCXX_INCLUDE_DIRS = ${LIBBSONCXX_INCLUDE_DIRS}")
|
message("LIBBSONCXX_LIBRARIES = ${LIBBSONCXX_LIBRARIES}")
|
|
|
file(GLOB COMMON_LIBRARIES ${LIBMONGOCXX_LIBRARIES} ${LIBBSONCXX_LIBRARIES})
|
|
|
SET(APP_SOURCE source/App/main.cpp)
|
|
|
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${BUILD_PATH}/App)
|
add_executable(App ${APP_SOURCE})
|
target_include_directories(App PUBLIC ${LIBMONGOCXX_INCLUDE_DIRS})
|
target_include_directories(App PUBLIC ${LIBBSONCXX_INCLUDE_DIRS})
|
|
|
target_link_libraries(App ${COMMON_LIBRARIES})
|
|
|
. . .
|
Unfortunately during the linking stage, I get these errors:
|
|
[100%] Linking CXX executable App/App
|
Undefined symbols for architecture x86_64:
|
"mongocxx::v_noabi::uri::uri(bsoncxx::v_noabi::string::view_or_value)", referenced from:
|
App::Initialize(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in main.cpp.o
|
"mongocxx::v_noabi::uri::~uri()", referenced from:
|
App::Initialize(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in main.cpp.o
|
"mongocxx::v_noabi::client::client(mongocxx::v_noabi::uri const&, mongocxx::v_noabi::options::client const&)", referenced from:
|
App::Initialize(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in main.cpp.o
|
"mongocxx::v_noabi::client::~client()", referenced from:
|
App::Initialize(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in .cpp.o
|
"mongocxx::v_noabi::instance::instance()", referenced from:
|
App::Initialize(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in main.cpp.o
|
"mongocxx::v_noabi::instance::~instance()", referenced from:
|
App::Initialize(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in main.cpp.o
|
ld: symbol(s) not found for architecture x86_64
|
clang: error: linker command failed with exit code 1 (use -v to see invocation)
|
make[3]: *** [App/App] Error 1
|
make[2]: *** [CMakeFiles/App.dir/all] Error 2
|
make[1]: *** [CMakeFiles/App.dir/rule] Error 2
|
make: *** [App] Error 2
|
I tried building using different c++17 polyfills just in case, no go. I also tried manually uninstalling mongo-cxx-driver and mongo-c-driver this time installing thru homebrew, but was met with the same errors.
In my research, the most relatable StackOverflow post is Using the mongodb cxx driver in a cmake c++ project, yet none of the solutions there work for me.
Operating System: macOS Sierra 10.12.6
IDE: CLion 2017.2.2 Build #CL-172.3968.17, built on August 22, 2017
CMake: 3.8.2
mongo-cxx-driver: 3.1.3
mongo-c-driver: 1.8.0
Any help or insight would be much appreciated, please feel free to ask me to clarify or add information where it may be unclear or missing.
Here is the code which is causing the error:
|
|
|
#include <cstdint>
|
#include <iostream>
|
#include <vector>
|
#include <bsoncxx/json.hpp>
|
#include <mongocxx/client.hpp>
|
#include <mongocxx/instance.hpp>
|
#include <mongocxx/uri.hpp>
|
#include <mongocxx/stdx.hpp>
|
|
|
using bsoncxx::builder::stream::close_array; |
using bsoncxx::builder::stream::close_document; |
using bsoncxx::builder::stream::document; |
using bsoncxx::builder::stream::finalize; |
using bsoncxx::builder::stream::open_array; |
using bsoncxx::builder::stream::open_document; |
|
|
mongocxx::instance instance{}; // This should be done only once. |
mongocxx::uri uri("mongodb://localhost:27017"); |
mongocxx::client client(uri);
|
Note: I also have opened a StackOverflow question as this is a fairly time sensitive issue for me.