Linking MongoDB CXX driver with Qt app project - c++

Our team is stuck on a problem with connecting MongoDB CXX driver to QtCreator 5.10. We have builded and compiled mongo-c-driver and mongo-cxx-driver with CMake and msbuild (VS 2017 compiler). We created test project in Visual Studio added needed includes, libs, dependencies (also we copied dll files to debug folder) and it worked, we have connected to our MongoDB server. But as we were trying to add those libs to QtCreator project and run test project we got this kind of errors:
C:\Qt-projects\test_mongo\main.cpp:24: error: undefined reference to `_imp___ZN8mongocxx7v_noabi8instanceC1Ev'
We tried every combination of adding to .pro file these commands: LIBS += , INCLUDE_PATH +=. And we also tried to copy dll's to debug/release build folder.
The question is, how properly add all the includes, libs, dll's to .pro file, so the QT project could recognize MongoCXX driver?
P.S. we used this tutorial to create test project in VS2017:
Configuration Manager > Active Solution Platform: x64
C/C++ > Additional Include Directories: C:\mongo-c-driver\include\libbson-
1.0;C:\mongo-c-driver\include\libmongoc-1.0;C:\mongo-cxx-
driver\include\bsoncxx\v_noabi;C:\mongo-cxx-
driver\include\mongocxx\v_noabi;C:\Program Files\boost\boost_1_62_0;
Linker > Additional Library Directories: C:\mongo-cxx-driver\lib;
Linker > Input > Additional Dependencies: bsoncxx.lib;mongocxx.lib;
Build Events > Post-Build Event: COPY "C:\mongo-cxx-driver\bin\bsoncxx.dll"
"$(OutDir)";COPY "C:\mongo-cxx-driver\bin\mongocxx.dll" "$(OutDir)";COPY
"C:\mongo-c-driver\bin\libmongoc-1.0.dll" "$(OutDir)";COPY "C:\mongo-c-
driver\bin\libbson-1.0.dll" "$(OutDir)";

Related

Error : LNK1104 cannot open file 'pthread.lib'

I am trying to compile a native Linux C++ application in Windows using Visual Studio 2017. The app uses WebRtc's Acoustic Echo Cancellation(AEC) APIs to negate echo on wav files. Following is the CmakeLists.txt file:
cmake_minimum_required(VERSION 2.8)
project(wav-aec)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
add_subdirectory(gflags)
add_definitions("-DWEBRTC_NS_FLOAT -DWEBRTC_WIN -DNOMINMAX")
#-DWEBRTC_UNTRUSTED_DELAY -DWEBRTC_LINUX -DWEBRTC_POSIX
include_directories(
webrtc
webrtc/webrtc/common_audio/signal_processing/include
webrtc/webrtc/modules/audio_coding/codecs/isac/main/include
)
set(WEBRTC_SRC_
base/buffer.cc
base/checks.cc
...
...
#system_wrappers/source/rw_lock_posix.cc
system_wrappers/source/trace_impl.cc
#system_wrappers/source/trace_posix.cc
)
function(prepend_path var prefix)
set(listVar "")
foreach(f ${ARGN})
list(APPEND listVar "${prefix}/${f}")
endforeach(f)
set(${var} "${listVar}" PARENT_SCOPE)
endfunction(prepend_path)
prepend_path(WEBRTC_SRC webrtc/webrtc ${WEBRTC_SRC_})
add_executable(webrtc-audioproc webrtc-audioproc.cpp ${WEBRTC_SRC})
target_link_libraries(webrtc-audioproc gflags pthread)
When I try to build it, I get the following errror:
Error : LNK1104 cannot open file 'pthread.lib'
Here is the link to the only linux dependent source file(cpp) of the project:
https://github.com/lschilli/wav-aec/blob/master/webrtc-audioproc.cpp
What will be the right approach to port the code from Linux to windows?
Whats is Windows equivalent of gflags and pthread? And what necessary changes needs to go to CmakeLists.txt?
P.S: I have already added pthread header, dll and libs to Visual Studio directory manually.
If 'missing pthread library' is the only error, you can use pthread-w32. We have successfully used it in some of our cross-platform apps requiring pthread.
They have libraries for both 64-bit and 32-bit. You can download and add it into your project. You haven't mentioned your toolset - their libraries are named differently depending on your toolset (MSVC or GNU) so you need to pick the right one. Check out their FAQ.
Hope it helps.
You need to us the actual lib file which is typically not "pthread.lib". It's most likely "pthreadVC3.lib" or "pthreadVC2.lib". Find the actual name by looking in the lib directory of your source package. You might see other lib files in there like "pthreadVCE3.lib" and "pthreadVSE3.lib", but you want to link "pthreadVC3.lib".
You can either add this in the project settings, or add the following code:
#pragma comment(lib,"pthreadVC3.lib")
To add it to the project settings:
Go to project properties->Configuration Properties->Linker->General and add your library path to Additional Library Directories
Go to project properties->Configuration Properties->Linker->Input and add the lib file (such as "pthreadVC3.lib") to Additional Dependencies
Make sure you have the correct version of pthread to match your compile settings, ie x86/x64.
In my case, I am using VCPkg for package management and I installed pthreads using the following commands:
vcpkg install pthread:x86-windows
vcpkg install pthread:x64-windows
And my package lib directory is "C:\vcpkg\installed\x64-windows\lib"
I additionally had to add the following to my project settings as vcpkg wasn't integrating automatically:
Go to project properties->Configuration Properties->VC++ Directories and add "C:\vcpkg\installed\x64-windows\include" to Include Directories
Go to project properties->Configuration Properties->VC++ Directories and add "C:\vcpkg\installed\x64-windows\lib" to Library Directories

Specify external library for linux from Visual Studio 2017

I'm developing linux(ubuntu) c++ project from Visual Studio 2017. I want to integrate googletest into my code. I have installed googletest and run test example according following tutorial. Everything works fine when I run it from bash terminal using cmake.
Now I need to run it using VS. For that I need to specify path to /usr/lib/libgtest.a from VS. I added /usr/lib into Linker->General->Additional Library Directories and added libgtest.a into Linker->Input->Additional Dependencies. But compiler still cannot link the library:
g++: error: libgtest.a: No such file or directory
Try omit "lib" and ".a" from the file name as these portions of the filename seem to be added by the linker itself. In your case you would reference "gtest".
Try Configuration Properties -> Linker->Input->Library Dependencies with "gtest". Note: libgtest.a must in standard location so linker can search.

OpenCV made by Cmake does not contain any libaries

I am trying to setup OpenCV for Visual Studio 2015, x64, in windows.
I have followed this guide to get OpenCV up and running, however after the CMake Part, i am not sure if everything has gone well.
1- my build file does not contain any lib folder
2- i am confused as where should i set the environment variable for it
3- I assume in visual studio i have to set path for the libraries, but i
don't see any in my build
4- my include folder has a weird install file
pic1: here is a picture of my OpenCV file that cMake built
bin folder is empty
pic2:include folder contents
CMake does not build your library. It sets your build environment, such as designating the install directory for the OpenCV.
So you need to actually build your OpenCV library, then you'll have your include and lib files at the place you've designated as the install directory (cmake_install_prefix in the CMake option).
If you've done your CMake step successfully, you can build your OpenCV by building ALL_BUILD project in your Visual Studio project explorer, and building INSTALL project after that.

Eclipse doesn't see include files when checking syntax but does when building or running the application

I started with building my project with CMake by using the cmake <folder> -G"Eclipse CDT4 - Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug command (I'm using Ubuntu 14.04). Say the results were written to /home/student/tempFolder/HelloFrameworkApp folder.
The thing is that I have header files needed for he application in /home/student/git/fagot/sw/branches/head/framework/include folder. This is also described in CMakeLists so after I import my project from /home/student/tempFolder/HelloFrameworkApp to Eclipse as existing code as makefile project, it can successfully be built and runs just as expected.
But in the code edit area there are tons of red underlining which makes it clear that Eclipse can't see the include folder I mentioned before. I tried going to Properties -> C/C++ General -> Paths and symbols and adding that include folder to all configurations and languages but it didn't help.
Any suggestions?
CMake creates an Eclipse project for you. Therefore you need to use: Import->General->Existing Project into Workspace.

How to debug external .cpp files on Eclipse CDT ( C++ )

I have big project in directory "project". I build this project using cmake into another directory "build". For coding I try to use Eclipse, but when I try to import my code into Eclipse ( File->Import->C/C++->Existing Code as Makefile Project ), of course I can import only "build" directory without "project" ( because make file are in "build" and "project" is empty for Eclipse ).
When I run my build in debug mode, I can debug only binary data, because debuger can't seen sources in "project" directory. How I can setup debuger for use sources from "project" directory? Thanks if some one answered!
import your Project (rootdir not build) as MakeFile Project into the Workspace (select GNU Toolschain or Linux GCC). Now open your project properties -> c++ build and select the build folder inside your project.
Now you can compile it and create a new run configuration for debugging.
Greez ZuSe
Edit:
I assume your rootfolder looks like this
cmake/
CmakeList.txt
src/
dep/
../
now you create a folder build
you switch to build and run cmake cmake ../ -flags (no eclipse-project, use default gcc)
After you have done this u can import your rootfolder to eclipse cdt and select root/build as build folder. Where is the problem? Eclipse CDT only wants to now where the makefile is at buildtime (thats why you manually need to select the buildfolder)
You do not need sources in your workspace to debug the application if you built the application on your system - build directory & paths are in your executable debug information.
Make sure you pass -g both to the compiler and linker.
Try command-line GDB - it should find sources as well.
You may setup custom source mapping in the Eclipse CDT debugger when setting up the launch configuration - but I believe this is mostly for cases when sources were moved after you built the application or if you built on another system.
Here is how i do it, step by step. It is a simple cmake project i downloaded from github.
Works like a harm.
imagebam.com http://thumbnails101.imagebam.com/23645/1e5c42236445850.jpg
imagebam.com http://thumbnails101.imagebam.com/23645/64cb47236445860.jpg