cmake _ITERATOR_DEBUG_LEVEL and RuntimeLibrary mismatch detected - c++

I am learning to build library with the following command
cmake -S . -B .\build\ -DCMAKE_BUILD_TYPE=Debug
cmake --build .\build\
I am getting the following errors during cmake --build .\build\
error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj
error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MD_DynamicRelease' doesn't match value 'MDd_DynamicDebug' in main.obj
I was referring the question at the error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj to solve the error error LNK2038: mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in main.obj but would like to know how to implement their solution using cmake. I referred the answer to solve the problem but it didn't solve the error.
Second problem is that I can't understand why MD_DynamicRelease is being built even though I added the option -DCMAKE_BUILD_TYPE=Debug.
Root CMakeLists.txt File
cmake_minimum_required(VERSION 3.16)
project(CppProjectTemplate VERSION 1.0.0 LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(MY_LIBRARY_NAME Library)
#Chapter 22 Starts Here --> Needs to be a cmake project else can't be used
include(FetchContent)
FetchContent_Declare(
nlohmann_json # Must be the same name as mentioned in the main (root) cmake project file
GIT_REPOSITORY https://github.com/nlohmann/json
GIT_TAG v3.11.2
GIT_SHALLOW TRUE #Won't clone recurrsively
)
FetchContent_MakeAvailable(nlohmann_json)# Must be the same name as mentioned in the main (root) cmake project file
FetchContent_Declare(
fmt # Must be the same name as mentioned in the main (root) cmake project file
GIT_REPOSITORY https://github.com/fmtlib/fmt
GIT_TAG 9.1.0
GIT_SHALLOW TRUE #Won't clone recurrsively
)
FetchContent_MakeAvailable(fmt)# Must be the same name as mentioned in the main (root) cmake project file
FetchContent_Declare(
spdlog # Must be the same name as mentioned in the main (root) cmake project file
GIT_REPOSITORY https://github.com/gabime/spdlog
GIT_TAG v1.11.0
GIT_SHALLOW TRUE #Won't clone recurrsively
)
FetchContent_MakeAvailable(spdlog)# Must be the same name as mentioned in the main (root) cmake project file
FetchContent_Declare(
cxxopts # Must be the same name as mentioned in the main (root) cmake project file
GIT_REPOSITORY https://github.com/jarro2783/cxxopts
GIT_TAG v3.0.0
GIT_SHALLOW TRUE #Won't clone recurrsively
)
FetchContent_MakeAvailable(cxxopts)# Must be the same name as mentioned in the main (root) cmake project file
FetchContent_Declare(
Catch2 # Must be the same name as mentioned in the main (root) cmake project file
GIT_REPOSITORY https://github.com/catchorg/Catch2
GIT_TAG v2.13.9
GIT_SHALLOW TRUE #Won't clone recurrsively
)
FetchContent_MakeAvailable(Catch2)# Must be the same name as mentioned in the main (root) cmake project file
# Chapter 22 Ends Here
# Enable/Disable option using -D<Option-Name>=1 or 0 e.g. -DCOMPILE_EXECUTABLE=1
option(COMPILE_EXECUTABLE "Whether to compile the executable" ON)
add_subdirectory(src)
add_subdirectory(test)
src folder
my_lib.hh
#pragma once
#include <cstdint>
void print_hello_world(void);
std::uint32_t factorial(std::uint32_t number);
my_lib.cc
#include <iostream>
#include "my_lib.hh"
#include <nlohmann/json.hpp>
#include <fmt/format.h>
#include <spdlog/spdlog.h>
#include <cxxopts.hpp>
/**
* #brief Print out Hello, World!!! and print the version of nlohmann-json, fmt-format, cxxopts and spdlog library
*
*/
void print_hello_world(void)
{
std::cout << "Hello, World!!!" << std::endl;
std::cout << "Json Lib Version (Inside print_hello_world) : "
<< NLOHMANN_JSON_VERSION_MAJOR << "."
<< NLOHMANN_JSON_VERSION_MINOR << "."
<< NLOHMANN_JSON_VERSION_PATCH << std::endl;
std::cout << "FMT Version (Inside print_hello_world) : "
<< FMT_VERSION << std::endl;
std::cout << "cxxopts Version (Inside print_hello_world) : "
<< CXXOPTS__VERSION_MAJOR << "."
<< CXXOPTS__VERSION_MINOR << "."
<< CXXOPTS__VERSION_PATCH << std::endl;
std::cout << "spdlogs Version (Inside print_hello_world) : "
<< SPDLOG_VER_MAJOR << "."
<< SPDLOG_VER_MINOR << "."
<< SPDLOG_VER_PATCH << std::endl;
}
std::uint32_t factorial(std::uint32_t number)
{
return number <= 1 ? number : factorial(number-1) * number;
}
src CMakeLists.txt
set(
LIBRARY_SOURCES
"my_lib.cc"
)
set(LIBRARY_HEADERS
"my_lib.hh")
add_library(${MY_LIBRARY_NAME} STATIC ${LIBRARY_SOURCES} ${LIBRARY_HEADERS})
target_include_directories(${MY_LIBRARY_NAME} PUBLIC
"./"
"${CMAKE_BINARY_DIR}/configured_files/include"
)
target_link_libraries(${MY_LIBRARY_NAME} PUBLIC
nlohmann_json::nlohmann_json
cxxopts::cxxopts
fmt::fmt
spdlog::spdlog
)
Test Directory
CMakeLists.txt
set(TEST_PROJECT "TestExecutable")
set(TEST_SOURCES "main.cc")
set(TEST_INCLUDE "./")
add_executable(${TEST_PROJECT} ${TEST_SOURCES})
target_include_directories(${TEST_PROJECT} PUBLIC ${TEST_INCLUDE})
target_link_libraries(${TEST_PROJECT} PUBLIC ${MY_LIBRARY_NAME} Catch2::Catch2)
main.cc
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include "my_lib.hh"
TEST_CASE("Factorial are computed", "[Factorial]")
{
REQUIRE(factorial(1) == 1);
REQUIRE(factorial(2) == 2);
REQUIRE(factorial(3) == 6);
REQUIRE(factorial(10) == 3628800);
}

Based on your reply to my comment the issue is in this line:
target_link_libraries(${TEST_PROJECT} PUBLIC ${MY_LIBRARY_NAME} Catch2::Catch2)
I've faced similar issues and it's caused by not linking the debug library of Catch2 in DEBUG builds (but instead the release libraries). To fix this you need to use generator expressions for linking Catch2. I do not have a concrete example (it's been years since I've used Catch2), but you ideally need to link the actual Catch2 library without using the alias Catch2::Catch2 and use generator expressions to specify the debug library. e.g. you need something like:
target_link_libraries(${TEST_PROJECT} PUBLIC ${MY_LIBRARY_NAME} Catch2<$<$CMAKE_BUILD_TYPE:DEBUG>d>)
Where Catch2 is the actual library target and not the alias i.e. Catch2::Catch2. The generator expression basically expands to Catch2d when CMAKE_BUILD_TYPE == DEBUG.
EDIT: As DarkSorrow mentions in the comments below, this has resolved the issue for him
target_link_libraries(${TEST_PROJECT} PUBLIC ${MY_LIBRARY_NAME} Catch2$<$<CONFIG:Debug>:d>)

Related

cmake: build dependency downloaded with ExternalProject_Add before hand

I'm trying to get my test program main.cpp to link against a an externally downloaded library (in this case fmt 8.1.1) via cmake's 'ExternalProject_Add' function as follows
CMakeLists.txt
cmake_minimum_required(VERSION 3.23)
project(test)
set(CMAKE_CXX_STANDARD 20)
include(ExternalProject)
ExternalProject_Add(fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
GIT_TAG 8.1.1
CMAKE_ARGS -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_STANDARD=20 -DFMT_TEST=OFF -DFMT_DOC=OFF -DFMT_INSTALL=ON -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/fmt-build
STEP_TARGETS build
)
set(fmt_BINARY_DIR "${CMAKE_BINARY_DIR}/fmt-prefix/src/fmt-build")
set(fmt_SOURCE_DIR "${CMAKE_BINARY_DIR}/fmt-prefix/src/fmt/include")
add_executable(${PROJECT_NAME} main.cpp)
add_dependencies(${PROJECT_NAME} fmt-build) # does not have an effect
target_link_libraries(${PROJECT_NAME} PRIVATE ${fmt_BINARY_DIR}/libfmt.a)
target_include_directories(${PROJECT_NAME} PUBLIC ${fmt_SOURCE_DIR})
main.cpp
#include <chrono>
#include <fmt/core.h>
#include <fmt/chrono.h>
int main() {
const auto now = std::chrono::system_clock::now();
fmt::print("The time is {}", now);
return 0;
}
The test program main.cpp runs OK if I build the target fmt-build before hand, but complains that
ninja: error: 'fmt-prefix/src/fmt-build/libfmt.a', needed by 'test', missing and no known rule to make it
indicating that the dependency fmt-build must be built before hand. While that's doable, how do I get cmake to autmoatically build fmt-build as a dependency for test without haing to run it manually first? I thought the line add_dependencies(${PROJECT_NAME} fmt-build) should take care of that but evidently it does not.
Based on what #Tsyvarev commented, simply adding the line
BUILD_BYPRODUCTS ${CMAKE_BINARY_DIR}/fmt-prefix/src/fmt-build/libfmt.a
to the ExternalProject_Add call does the trick, and one does not have to manually build fmt-build before hand.

AWS SDK static linking: libcrypto.so.1.0.0: cannot open shared object file

I am trying to build AWS SDK for c++ with static linking, so I can use it as a binary inside AWS Lambda function.
Steps which I took are as follows:
git clone https://github.com/aws/aws-sdk-cpp.git.
mkdir build && cd build
cmake .. -DBUILD_SHARED_LIBS=OFF -DBUILD_ONLY="s3" -DENABLE_TESTING=OFF -DFORCE_SHARED_CRT=OFF (which created libaws-cpp-sdk-s3.a inside aws-cpp-sdk-s3 directory)
Now my source CMakeLists.txt looks like below
cmake_minimum_required(VERSION 3.1)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_BUILD_TYPE "Release")
project(executable LANGUAGES CXX)
add_executable(${PROJECT_NAME} "execute_code.cpp")
set(OPENSSL_USE_STATIC_LIBS TRUE)
find_package(OpenSSL REQUIRED)
target_link_libraries(${PROJECT_NAME} PRIVATE OpenSSL::Crypto)
set(aws-sdk-cpp_DIR "<path to aws-sdk-cpp/build>")
find_package(aws-sdk-cpp)
link_libraries(aws-cpp-sdk-core)
target_link_libraries(executable PRIVATE aws-cpp-sdk-s3 aws-cpp-sdk-core)
target_compile_features(${PROJECT_NAME} PRIVATE "cxx_std_11")
target_compile_options(${PROJECT_NAME} PRIVATE
"-Wall"
"-Wextra"
"-Wconversion"
"-Wshadow"
"-Wno-sign-conversion")
#set(CMAKE_EXE_LINKER_FLAGS "-static -static-libgcc -static-libstdc++")
include_directories(${PROJECT_SOURCE_DIR})
I am aware that AWS SDK for c++ requires OpenSSL and I have added that inside CMakeLists and when I run make after Cmake command, tt shows
-- Found OpenSSL: /usr/lib/x86_64-linux-gnu/libcrypto.a (found version "1.0.2g")
so project is able to find static libcrypto. But when I am deploying it on AWS lambda, it gives error error while loading shared libraries: libcrypto.so.1.0.0: cannot open shared object file: No such file or directory\n.
Can anyone tell me how do I debug this or If I am missing anything? I tried searching for it, but couldn't find anything useful for static linking.
Here is my execute_code.cpp:
#include <aws/core/Aws.h>
#include <aws/s3/S3Client.h>
#include <aws/s3/model/Bucket.h>
#include<iostream>
int main(int argc, char** argv) {
Aws::SDKOptions options;
Aws::InitAPI(options);
{
// snippet-start:[s3.cpp.list_buckets.code]
Aws::S3::S3Client s3_client;
auto outcome = s3_client.ListBuckets();
if (outcome.IsSuccess())
{
std::cout << "Your Amazon S3 buckets:" << std::endl;
Aws::Vector<Aws::S3::Model::Bucket> bucket_list =
outcome.GetResult().GetBuckets();
for (auto const &bucket : bucket_list)
{
std::cout << " * " << bucket.GetName() << std::endl;
}
}
else
{
std::cout << "ListBuckets error: "
<< outcome.GetError().GetExceptionName() << " - "
<< outcome.GetError().GetMessage() << std::endl;
}
// snippet-end:[s3.cpp.list_buckets.code]
}
Aws::ShutdownAPI(options);
It will also be helpful if anyone can tell how can I deploy shared libraries on AWS lambda.
Edit: I was able to solve this by building on Amazon Linux instead of Ubuntu machine.

Undefined reference with boost asio ssl [duplicate]

I have a question for people who work with CMakeList.txt in C++. I want to use Podofo project (a project to parse & create pdf).
So my main function is simple as:
#include <iostream>
#include <podofo/podofo.h>
int main() {
PoDoFo::PdfMemDocument pdf;
pdf.Load("/Users/user/path/to.pdf");
int nbOfPage = pdf.GetPageCount();
std::cout << "Our pdf have " << nbOfPage << " pages." << std::endl;
return 0;
}
My CMakeList.txt is:
cmake_minimum_required(VERSION 3.7)
project(untitled)
set(CMAKE_CXX_STANDARD 14)
set(SOURCE_FILES main.cpp)
add_executable(untitled ${SOURCE_FILES})
But I am stuck with this error:
/usr/local/include/podofo/base/PdfEncrypt.h:44:10: fatal error: 'openssl/opensslconf.h' file not found
#include <openssl/opensslconf.h
I tried to include with find_package, find_library .. setting some variables but I do not find the way.
My env is:
macOS
Clion
Podofo installed via home-brew in /usr/local/podofo
OpenSSL installed via home-brew in /usr/local/opt/openssl
Thanks by advance community !!
find_package is the correct approach; you find details about it here.
In your case, you should add these lines:
find_package(OpenSSL REQUIRED)
target_link_libraries(untitled OpenSSL::SSL)
If CMake doesn't find OpenSSL directly, you should set the CMake variable OPENSSL_ROOT_DIR.

Building mongo-cxx-driver using CMake ExternalProject_Add

I am trying to build mongo-cxx-driver in a CMake based project. This project is supposed to build on Windows, macOS and in an ubuntu container and I want to ensure that my software on all these platforms will use the same driver version so I cannot afford installing the driver and its dependencies via apt-get, brew etc. So I am left with one option: ExternalProject_Add. But I am having difficulty making that work given how libmongoc is setup.
Below is the CMake module I currently have.
include(ExternalProject)
set(libmongoc_CMAKE_ARGS
"-DCMAKE_BUILD_TYPE:STRIING=${CMAKE_BUILD_TYPE}"
"-DENABLE_TESTS:BOOL=OFF"
"-DENABLE_STATIC:BOOL=OFF"
"-DENABLE_EXAMPLES:BOOL=OFF"
"-DENABLE_EXTRA_ALIGNMENT:BOOL=OFF"
)
set(mongocxx_CMAKE_ARGS
"-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
"-DCMAKE_BUILD_TYPE:STRIING=${CMAKE_BUILD_TYPE}"
"-DBUILD_SHARED_LIBS:BOOL=ON"
"-DENABLE_TESTS:BOOL=OFF"
"-DENABLE_EXAMPLES:BOOL=OFF"
"-DBSONCXX_POLY_USE_BOOST:BOOL=ON"
"-DBSONCXX_POLY_USE_MNMLSTC:BOOL=OFF"
"-Dlibbson-1.0_DIR:PATH=${OTS_DEPDENDENCIES_DIR}/libmongoc/src/libbson"
)
if (NOT TARGET libmongoc)
ExternalProject_Add(
libmongoc
GIT_REPOSITORY "https://github.com/mongodb/mongo-c-driver.git"
GIT_TAG "1.12.0"
SOURCE_DIR "${OTS_DEPDENDENCIES_DIR}/libmongoc"
BINARY_DIR "${OTS_DEPDENDENCIES_DIR}/libmongoc"
CMAKE_ARGS "${libmongoc_CMAKE_ARGS}"
INSTALL_COMMAND ""
)
endif()
if (NOT TARGET mongocxx)
ExternalProject_Add(
mongocxx
GIT_REPOSITORY "https://github.com/mongodb/mongo-cxx-driver.git"
GIT_TAG "r3.3.1"
SOURCE_DIR "${OTS_DEPDENDENCIES_DIR}/mongocxx"
BINARY_DIR "${OTS_DEPDENDENCIES_DIR}/mongocxx"
CMAKE_ARGS "${mongocxx_CMAKE_ARGS}"
INSTALL_COMMAND ""
DEPENDS libmongoc
)
endif()
Note the CMAKE option libbson-1.0_DIR given as one of the CMAKE_ARGS for mongo-cxx-driver. I am skeptic about it and I believe that may be the culprit. With it I get the following error:
CMake Error at ${OTS_DEPENDENCIES_DIR}/libmongoc/src/libbson/libbson-1.0-config.cmake:30 (message):
File or directory
${OTS_DEPENDENCIES_DIR}/include/libbson-1.0
referenced by variable BSON_INCLUDE_DIRS does not exist !
Call Stack (most recent call first):
${OTS_DEPENDENCIES_DIR}/libmongoc/src/libbson/libbson-1.0-config.cmake:46 (set_and_check)
src/bsoncxx/CMakeLists.txt:81 (find_package)
which kind of makes sense because src/bsoncxx/CMakeLists.txt:81 reads:
get_filename_component(PACKAGE_PREFIX_DIR "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)
set_and_check (BSON_INCLUDE_DIRS "${PACKAGE_PREFIX_DIR}/include/libbson-1.0")
which makes CMake end up looking for libbson-1.0 in ${OTS_DEPDENDENCIES_DIR}/include that does not exist. If only, I could tell cmake, "hey don't run this find_package" I can give you the path to INCLUDE_DIR, LIBRARIES and DEFINITIONS myself.
If I remove this option, I get the following error:
CMake Error at src/bsoncxx/CMakeLists.txt:81 (find_package):
By not providing "Findlibbson-1.0.cmake" in CMAKE_MODULE_PATH this project
has asked CMake to find a package configuration file provided by
"libbson-1.0", but CMake did not find one.
Could not find a package configuration file provided by "libbson-1.0"
(requested version 1.10.0) with any of the following names:
libbson-1.0Config.cmake
libbson-1.0-config.cmake
Add the installation prefix of "libbson-1.0" to CMAKE_PREFIX_PATH or set
"libbson-1.0_DIR" to a directory containing one of the above files. If
"libbson-1.0" provides a separate development package or SDK, be sure it
has been installed.
which is not very odd either because CMake tries to find_package libbson-1.0 but cannot figure out where it is installed.
preliminary remarks
While looking at the details, here are few preliminary comments:
Use different directory for SOURCE_DIR and BINARY_DIR
Instead of CMAKE_ARG, prefer CMAKE_CACHE_ARGS
libbson-1.0_DIR should NOT be set to a source directory, instead if should be set to a build directory containing a config-file package (link below provide more details about this concept)
Make sure to always specify the type of CMake argument (-DCMAKE_CXX_COMPILER:PATH=${CMAKE_CXX_COMPILER} instead of -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER})
Do not set CMAKE_BUILD_TYPE for multi-configuration generator
Regarding this last point, this means that you should do the following:
set(EXTERNAL_PROJECT_OPTIONAL_CMAKE_CACHE_ARGS)
if(NOT DEFINED CMAKE_CONFIGURATION_TYPES)
list(APPEND EXTERNAL_PROJECT_OPTIONAL_CMAKE_CACHE_ARGS
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
)
endif()
In this post, you can learn how you could structure your project: Correct way to use third-party libraries in cmake project
working project allowing to compile the mongocxx "test.cpp"
Below is the content of CMakeLists.txt and test.cpp allowing to build an executable named <build-dir>/Test-build/test_mongocxx :
CMakeLists.txt:
cmake_minimum_required(VERSION 3.12)
set(CMAKE_CXX_STANDARD 11)
project(Test)
option(${PROJECT_NAME}_SUPERBUILD "Build ${PROJECT_NAME} and the projects it depends on." ON)
if(${PROJECT_NAME}_SUPERBUILD)
include(ExternalProject)
set(common_cmake_cache_args
-DCMAKE_CXX_COMPILER:PATH=${CMAKE_CXX_COMPILER}
)
if(NOT DEFINED CMAKE_CONFIGURATION_TYPES)
list(APPEND common_cmake_cache_args
-DCMAKE_BUILD_TYPE:STRING=${CMAKE_BUILD_TYPE}
)
endif()
ExternalProject_Add(libmongoc
GIT_REPOSITORY "https://github.com/mongodb/mongo-c-driver.git"
GIT_TAG "1.12.0"
GIT_PROGRESS 1
GIT_SHALLOW 1
SOURCE_DIR "${CMAKE_BINARY_DIR}/libmongoc"
BINARY_DIR "${CMAKE_BINARY_DIR}/libmongoc-build"
INSTALL_DIR "${CMAKE_BINARY_DIR}/libmongoc-install"
CMAKE_CACHE_ARGS
${common_cmake_cache_args}
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_BINARY_DIR}/libmongoc-install
-DENABLE_TESTS:BOOL=OFF
-DENABLE_STATIC:BOOL=OFF
-DENABLE_EXAMPLES:BOOL=OFF
-DENABLE_EXTRA_ALIGNMENT:BOOL=OFF
#INSTALL_COMMAND ""
)
set(libmongoc-1.0_DIR "${CMAKE_BINARY_DIR}/libmongoc-install/lib/cmake/libmongoc-1.0/")
set(libbson-1.0_DIR "${CMAKE_BINARY_DIR}/libmongoc-install/lib/cmake/libbson-1.0/")
ExternalProject_Add(libmongocxx
GIT_REPOSITORY "https://github.com/mongodb/mongo-cxx-driver.git"
GIT_TAG "r3.3.1"
GIT_PROGRESS 1
GIT_SHALLOW 1
SOURCE_DIR "${CMAKE_BINARY_DIR}/libmongocxx"
BINARY_DIR "${CMAKE_BINARY_DIR}/libmongocxx-build"
INSTALL_DIR "${CMAKE_BINARY_DIR}/libmongocxx-install"
CMAKE_CACHE_ARGS
${common_cmake_cache_args}
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_BINARY_DIR}/libmongocxx-install
-DBUILD_SHARED_LIBS:BOOL=ON
-DENABLE_TESTS:BOOL=OFF
-DENABLE_EXAMPLES:BOOL=OFF
-DBSONCXX_POLY_USE_BOOST:BOOL=OFF
-DBSONCXX_POLY_USE_MNMLSTC:BOOL=ON
-DBSONCXX_POLY_USE_STD:BOOL=OFF
-Dlibmongoc-1.0_DIR:PATH=${libmongoc-1.0_DIR}
-Dlibbson-1.0_DIR:PATH=${libbson-1.0_DIR}
DEPENDS
libmongoc
)
set(libmongocxx_DIR "${CMAKE_BINARY_DIR}/libmongocxx-install/lib/cmake/libmongocxx-3.3.1/")
set(libbsoncxx_DIR "${CMAKE_BINARY_DIR}/libmongocxx-install//lib/cmake/libbsoncxx-3.3.1/")
function(ExternalProject_AlwaysConfigure proj)
# This custom external project step forces the configure and later
# steps to run.
_ep_get_step_stampfile(${proj} "configure" stampfile)
ExternalProject_Add_Step(${proj} forceconfigure
COMMAND ${CMAKE_COMMAND} -E remove ${stampfile}
COMMENT "Forcing configure step for '${proj}'"
DEPENDEES build
ALWAYS 1
)
endfunction()
ExternalProject_Add(${PROJECT_NAME}
SOURCE_DIR "${CMAKE_SOURCE_DIR}"
BINARY_DIR "${CMAKE_BINARY_DIR}/${PROJECT_NAME}-build"
DOWNLOAD_COMMAND ""
UPDATE_COMMAND ""
CMAKE_CACHE_ARGS
${common_cmake_cache_args}
-D${PROJECT_NAME}_SUPERBUILD:BOOL=OFF
-Dlibbsoncxx_DIR:PATH=${libbsoncxx_DIR}
-Dlibmongocxx_DIR:PATH=${libmongocxx_DIR}
INSTALL_COMMAND ""
DEPENDS
libmongocxx
)
ExternalProject_AlwaysConfigure(${PROJECT_NAME})
return()
endif()
message(STATUS "Configuring inner-build")
find_package(libmongocxx REQUIRED)
add_executable(test_mongocxx test.cpp)
target_link_libraries(test_mongocxx PUBLIC ${LIBMONGOCXX_LIBRARIES})
target_include_directories(test_mongocxx PUBLIC ${LIBMONGOCXX_INCLUDE_DIRS})
target_compile_definitions(test_mongocxx PUBLIC ${LIBMONGOCXX_DEFINITIONS})
test.cpp (copied from https://mongodb.github.io/mongo-cxx-driver/mongocxx-v3/installation/#step-6-test-your-installation):
#include <iostream>
#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/json.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>
int main(int, char**) {
mongocxx::instance inst{};
mongocxx::client conn{mongocxx::uri{}};
bsoncxx::builder::stream::document document{};
auto collection = conn["testdb"]["testcollection"];
document << "hello" << "world";
collection.insert_one(document.view());
auto cursor = collection.find({});
for (auto&& doc : cursor) {
std::cout << bsoncxx::to_json(doc) << std::endl;
}
}

CMake Parse error Function missing ending ")". Instead found unterminated string with text ")

First of all I wanna say I am aware of below questions
Parse error. Function missing ending ")" CMAKE
CMake's execute_process and arbitrary shell scripts
But I couldn't understand solution provided in these questions, because I don't know much about cmake commands and also I think my problem context is different.
I am trying to compile https://github.com/openalpr/imageclipper this software.
I am following instructions in README file which says to do only two following commands
1.) cmake ./
2.) make
But while issuing first command I get this error ->
C:\Users\vishal tewatia\Downloads\imageclipper-master>cmake ./
CMake Error at CMakeLists.txt:25:
Parse error. Function missing ending ")". Instead found unterminated
string with text ")
ENDIF()
SET(SRC
src/imageclipper.cpp
)
ADD_EXECUTABLE( ${PROJECT_NAME} ${SRC} )
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} ${OpenCV_LIBS}
C:/boost_1_65_1/stage/lib
)".
-- Configuring incomplete, errors occurred!
See also "C:/Users/vishal tewatia/Downloads/imageclipper-master/CMakeFiles/CMakeOutput.log".
Below is CMakeLists.txt file
cmake_minimum_required (VERSION 2.6)
project(imageclipper)
SET(PROJECT_VERSION "0.1")
SET(OpenCV_DIR "C:\opencv\build\install\x64\vc15\bin\")
# Opencv Package
FIND_PACKAGE( OpenCV REQUIRED )
IF (${OpenCV_VERSION} VERSION_LESS 2.3.0)
MESSAGE(FATAL_ERROR "OpenCV version is not compatible :
${OpenCV_VERSION}")
ENDIF()
SET(SRC
src/imageclipper.cpp
)
ADD_EXECUTABLE( ${PROJECT_NAME} ${SRC} )
TARGET_LINK_LIBRARIES( ${PROJECT_NAME} ${OpenCV_LIBS}
C:/boost_1_65_1/stage/lib
)
I don't understand why is it says that function has missing ")" , because in CMakeLists.txt file all opened brackets are closed.
or if the error is regarding "C:/boost_1_65_1/stage/lib" this address not properly formatted , I am not sure then what to do , Please help.
ok , so I found the solution , All it needs is \\ instead of \ while setting OpenCV_DIR