I’m trying to use the mongocxx driver, which I installed from homebrew, with my cmake project, but when I build it, this error shows up:
fatal error: ‘bsoncxx/json.hpp’ file not found
So I tried to add this line to my CMakeLists:
include_directories(“/opt/homebrew/include/bsoncxx/v_noabi”)
and it hit me with another error:
fatal error: ‘core/optional.hpp’ file not found
I think that means it’s not trying to use optional in the std library, and instead trying to reference another implementation, perhaps a polyfill implementation. But how do I get it to reference std::optional? This is my CMakeLists without the above line:
cmake_minimum_required(VERSION 3.26)
project(${ProjectName})
set(CMAKE_CXX_STANDARD 20)
find_package(mongocxx REQUIRED)
find_package(bsoncxx REQUIRED)
add_executable(…)
target_link_libraries(NeuralNet_Training ${MONGOCXX_LIBRARIES} ${BSONCXX_LIBRARIES})
If anyone could help me, that would be great. Thanks!
Hi @Kevin_Liang
I gave it a try but couldn’t reproduce.
What does MONGOCXX_LIBRARIES
correspond to? Can you double check if it expands to
target_link_libraries(NeuralNet_Training PRIVATE mongo::mongocxx_shared)
target_link_libraries(NeuralNet_Training PRIVATE mongo::bsoncxx_shared)
I’m not sure how to check if it expands to that, but I replaced it anyway. It still gave the same error when I rebuilt the project. If it helps, I am currently running this on an M2 mac, which runs with ARM64. I’ve also added the include_directories lines, and that gives me “fatal error: ‘core/optional.hpp’ file not found”. This is my new CMakeLists.txt:
cmake_minimum_required(VERSION 3.26)
project(${ProjectName})
set(CMAKE_CXX_STANDARD 20)
include_directories(“/opt/homebrew/opt/mongo-cxx-driver/include/mongocxx/v_noabi”)
include_directories(“/opt/homebrew/opt/mongo-cxx-driver/include/bsoncxx/v_noabi”)
find_package(mongocxx REQUIRED)
find_package(bsoncxx REQUIRED)
add_executable(…)
target_link_libraries(${ProjectName} PRIVATE mongocxx_shared bsoncxx_shared)