Cannot load any image with CImg - c++

Any time I try to load an image I get an error saying CImg<unsigned char>::load(): Failed to recognize format of file. This happens for both jpg and png files.
I have found other posts about this saying to define cimg_use_png and cimg_use_jpeg, but then I get compilation errorstelling me I need png.n and jpeglib.h. Not sure where I'm supposed to get these from.
I'm not sure where I've gone wrong, so I don't know what to ask specifically. What's gone wrong?

If you want to open JPEG images, you need to install libjpeg and compile and link against it.
If you want to open PNG images, you need to install libpng and libz (for the compression) and compile and link against them.
At the moment, you should be able to use NetPBM format images - i.e. PBM, PGM and PPM.
Well, after two painful days of trying to work out how on Earth Visual Studio 2017 works, and how to install and integrate libjpeg with it, I can now explain how to install CImg and libjpeg on Windows.
Step 1
You need to have Visual Studio 2017 installed, which means you need Windows 7 with SP1 or better. When installing it, be sure to include "Windows 8.1 SDK"
Step 2
Download libjpeg from the IJG website. I took jpegsr9b.zip as it is the latest.
Step 3
Unzip the file and store it in a directory called libjpeg in your HOME directory.
Step 4
Go to Start>All Programs>Microsoft Visual Studio 2017>Visual Studio Tools > Developer Command Prompt for VS2017
Navigate to the directory you just unzipped. That will be something like this:
cd libjpeg
cd jpeg-9b
Step 5
Now you are going to need to find a file called win32.mak. I found mine in C:\Program Files\Microsoft SDKs\Windows\v7.0\Include. Yours may be somewhere else if you have Windows 8.1 SDK. Anyway, wherever it is, you need to add its containing directory to your includes. So I did:
set INCLUDE=%INCLUDE%;C:\Program Files\Microsoft SDKs\Windows\v7.0\Include
Step 6
Now run nmake to get your SLN - some weird Microsoft "solution" file. The command is:
nmake -f makefile.vc setup-v10
And you should get a file called jpeg.sln - hurray!
Step 7
Now start Visual Studio 2017, and open the jpeg.sln file you just created and build the project. It will create a Release directory in your libjpeg directory and inside the Release directory you will find jpeg.lib. You have now installed libjpeg.
Step 8
Close that project, and start a new C++ command-line project and write your CImg-based program. I wrote the simplest ever:
#define cimg_use_jpeg
#include "CImg.h"
using namespace cimg_library;
int main() {
CImg<unsigned char> img("C:\\Users\\Mark\\test.jpg");
img.display("Image");
return 0;
}
Step 9
Download CImg.h from Github, and save it in a directory called CImg in your HOME directory.
Step 10
Now tell Visual Studio where the include files (for CImg and libjpeg) are and where the library files (for libjpeg) are:
Step 11
Now tell Visual Studio 2017 that you want to link with libjpeg:
Step 12
Now you can compile, link and run your CImg program and load JPEG files and display them on the screen!
If you are using cmake on Linux/macOS, this answer shows you the way.
If you are compiling on macOS from the command line, you'll need to have XQuartz installed if you are display images on the screen, and you'll want something like this:
g++ -std=c++11 sample.cpp -o sample -I /opt/X11/include -L /opt/X11/lib -lX11 -ljpeg -lpng -lz

If you want CImg to work with jpeg or png images, you need to supply appropriate library.
Here's a tutorial how to install libjpeg to Visual Studio project. It's basically a 2019 update to Mark Setchell's answer.
How to install libjpeg to your project
Download jpegsr9c.zip (or newer) zip with source code
Extract the archive to a folder.
Copy the address of the folder extracted from archive
Search for Developer Command Prompt in Start menu
Navigate to extracted folder in Developer Command Prompt:
cd "C:\Users\HP\Downloads\temp\jpeg-9c"
Use right click to paste.
Run this command:
NMAKE /f makefile.vs setup-v15
Open jpeg.sln (which was now created).
In Solution Explorer, right click on the project. Select Retarget projects. Confirm prompt.
If you want to build your project for 64-bit platform: Right click on solution, select Configuration Manager and add new platform x64
Build solution
Now let's move to your project with CImg. Create a folder jpeglib in your project (it's IncludedLibraries\jpeglib for me). And add it to Project Properties -> C/C++ -> Additional Include Directories and to Project Properties -> Linker -> Additional Library Directories
Add jpeg.lib to Project Properties -> Linker -> Input -> Additional Dependencies
Copy x64/Release/jpeg.lib to this folder.
Search for all header files (`.h) in jpeg project and copy them to this folder.
Add #define cimg_use_jpeg before #include "CImg.h" in your project
All done! CImg is now able to read and save jpeg files.

Related

cannot see the file 'SDL2.lib'

This question is not a duplicate of cannot open file 'SDL2.lib' which discusses this same error but my problem is that I don't have an SDL2.lib file, if I can just see it I can make this work
I'm trying to set up the development environment for SDL2 by following Lazy Foo's tutorial.
Setting up SDL 2 on Visual Studio 2010 Ultimate
The tutorial is for Visual Studio 2010, I'm using Visual Studio Community Edition 2017. Is that a problem?
The problem starts when linking the libraries, there is no x86 or x64 folder inside the lib directory of SDL2's Windows Development libraries that I downloaded from SDL version 2.0.8 (stable).
So I specified it as lib/ instead of lib/x86 as it says in the tutorial.
These are the files inside the lib folder
$ ls
cmake/ libSDL2.dll.a libSDL2_test.a libSDL2main.a pkgconfig/
libSDL2.a libSDL2.la libSDL2_test.la libSDL2main.la
When building VS2017 is throwing an error saying that Cannot open file 'SDL2.lib'. Yeah, there is no such file. Do I need to do an additional step to get this file?
When I configured for CodeBlocks it works fine. What exactly am I doing wrong here? This may have an obvious answer but I'm not able to find it.
Library name `libSDL2.dll.a' indicates that it is not meant for use with VS C++ ( for dynamic link you need dll + lib, for static link you need only the lib ). You can construct a lib file from dll using dumpbin.exe and lib.exe. Your options are:
1) Download SDL source file in zip format from GitHub and create you own binaries.
2) Use vcpkg and install in just one command line ( recommended).
3) Download the SDL binaries from internet. ( you can have linker issues if the project configurations doesn't matches yours)

Install OpenCV 2.4.7 in Windows 7 for any editor

I have problem with installing OpenCV under Windows 7 x64. Following this. Downloaded executable and ran it. But I do not see any bin folder, instead there are 2 folders: build and source. What to do next I do not know, what to include to system path and how?
Note:
I am not using visual c++, instead I use devcpp editor.
The OpenCV windows installer comes as a self-extraction program. It essentially packs everything including the source files, docs, and most importantly, the pre-compiled files.
The pre-compiled files are located in build, and sources files are located in source. If you are intented to use opencv libraries solely, all you need to do is to
add build/include/ into your IDE additional include list.
selectively add build/lib/.. into the additional link list according to your vs version.
add build/bin/ to your system PATH, so your program can find them.

MySQL Connector C++ 64bit build from source in Visual Studio 2012

I am trying to build the mySQL Connector C++ from source in Visual Studio 2012 for the 64-bit architecture.
I understand that it depends on some boost header files and the C connector.
Running CMake produces a project file, but that project file doesn't compile because of a big list of very confusing errors which probably have to do something with the include files, and an even bigger list of warnings. The official site is of little help.
Could some one please list all the steps in successfully compiling the C++ Connector?
In order to build it you need to have the following:
You need to have installed either the MySQL server or the MySQL C Connector.
Have installed the Boost C++ libraries or have the source files for it. Please note that there is not need to build boost as you only need the header files.
Have CMake installed. When installing CMake it will ask you if you want it included in the PATH variable, you should select yes to make it easier later to use it.
Once you have all three available, open VS2012 x64 Native Tools Command Prompt and from the source root directory of the MySQL C++ Connector you need to issue the following:
set MYSQL_DIR=c:\PROGRA~1\MySQL\MYSQLC~1.1
cmake -G "Visual Studio 11 Win64" ^
-DBOOST_ROOT:STRING=C:\Users\user\DOWNLO~1\BOOST_~1\BOOST_~1 ^
-DMYSQL_LIB_DIR:STRING=c:\PROGRA~1\MySQL\MYSQLC~1.1\LIB
devenv.com MySQLCPPCONN.sln /build Release
The first command defines the MYSQL_DIR variable that points to the installation of the MySQL server or the MySQL C Connector.
The second command call cmake to prepare a VS project that will be 64bit. There seems to be a problem with the MYSQL_LIB_DIR variable and it does not get generated, so we need to define it manually. MYSQL_LIB_DIR has the value of MYSQL_DIR ending with a \LIB.
Third command is optional, it will build the project from command prompt without opening VS.
It is recommended that you use the DOS paths for the variables.
To do that, navigate to the directory you want to convert to DOS path and call for %I in (.) do echo %~sI. It will give you the converted path.
It's really tough task and I've spent lot of hours figuring this out.
There are two issues here:
C++ Connector and MySQL libraries they have provided have been generated with Visual Studio 2010. Hence we can not use them as it is under VS2012 (It gives version mismatch error)
They also have not specified exact compiler options under which they have compiled these libraries. If our compiler settings are different, we'll end up in lots and lots of (especially linker related) errors.
Considering these facts, the only way is to build ourselves these libraries. Building MySQL is quick but building connector is little complicated.
Here are steps I am sharing. In my case I wanted to link these libraries statically with my project so I built these libraries accordingly. You may want to make relevant changes wherever necessary as per your need.
Before continuing with these steps, please download and install CMake on your system.
Steps to build MySQL server:
Download MySQL source. Extract them. Go in extracted folder in command prompt.
Create BLD forder
Go in BLD folder through command prompt
Run
cmake .. -G "Visual Studio 11 2012 Win64"
It will create MySQL.sln
Open MySQL.sln in Visual Studio and build only 'mysqlclient' library (as only this would be needing by application)
This will build libraries in mysql-5.6.24\BLD\libmysql\< Configuration > folder which we link in our project.
Steps to build C++ connector:
Download mysql-connector-c++ source. Extract it. Go in extracted folder in command prompt.
Create BLD forder
Go in BLD folder through command prompt
Run this command (Make sure we've built MySQL server before this, in Release and Debug mode. Also make sure we've downloaded Boost sources)
cmake .. -DMYSQL_INCLUDE_DIR="..\..\mysql-5.6.24\include" -DMYSQL_LIB_DIR:STRING="..\mysql-5.6.24\BLD\libmysql\Release" -DBOOST_ROOT:STRING="..\Boost\boost_1_54_0" -DMYSQL_CLIENT_STATIC_LINKING=1 -G "Visual Studio 11 2012 Win64"
It will create MYSQLCPPCONN.sln
Open MYSQLCPPCONN.sln in Visual Studio and make changes to 'mysqlcppconn-static' project:
A. Under C/C++ -> General -> Additional Include Directories put this (for All Configurations)
nativeapi;..\;..\..\;..\cppconn;..\..\cppconn;..\..\..\mysql-5.6.24\include;..\..\..\mysql-5.6.24\BLD\include;..\..\..\Boost\boost_1_54_0
B. In Code Genaration, change Runtime Library to Multithreaded (Debug or non-Debug depends on configuration) and NOT DLL
C. Under Librarian -> All Options keep "Additional Options" and "Ignore Specific Default Libraries" to blank (for All Configurations)
D. Under Librarian -> General keep "Ignore Specific Default Libraries" to blank (for All Configurations)
Build only 'mysqlcppconn-static' library project (as only this would be needing by application to connect to MySQL server)
This would generate library in mysql-connector-c++-1.1.5\BLD\driver\< Configuration > folder which we link in our project.

Getting LibCurl to work with Visual Studio 2013

I am having trouble getting LibCurl to work with Visual Studio 2013. I downloaded the current version (curl-7.33.0) and tried following the instructions I found on this site: Using LibCurl with Visual 2010
But I can't find curllib.lib in the folder I downloaded. And I am still getting errors:
After searching the internet for more help. I now get these error messages. There appears to be a problem with linking to libcurl.lib?
This is what I have configured:
Inside /lib I have libcurl.lib and libcurl.dll
UPDATE
I downloaded this release for Win32 MSVC: http://curl.haxx.se/download.html#Win32
After adding the libcurl libraries and successfully compiling, I am now getting this error message:
The application was unable to start correctly (0xc000007b). Click OK to close the application.
Here is the sample code I am trying to run:
#include <iostream>
#include <stdio.h>
#include <curl/curl.h>
int main(void)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://google.com");
res = curl_easy_perform(curl);
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}
FINAL UPDATE
I believe I have gotten LibCurl to work with Visual Studio 2013 now. Persistence ftw!
Although, after spending hours trying to solve these error messages, I am a little hesitant at saying everything is working fine now. That is why I am putting a bounty on this question to get clear and concise instructions on getting LibCurl to work with Visual Studio 2013.
This is what I did to get it to work:
First, download the Win32 MSVC package here: http://curl.haxx.se/download.html#Win32
For these instructions sake, let's say you downloaded to C:\LibCurl
Start a new project in Visual Studio. Go to Project|Project Properties|VC++ Directories|Include Directories|
Add the path to the include directory inside the downloaded package. (C:\LibCurl\include)
Next, go to Project|Project Properties|Linker|General|Additional Library Directories|
Add the path to the lib directory. (Where curllib.dll is located)
Then, go to Project|Project Properties|Linker|Input|Additional Dependencies|
And add curllib.lib
Now if you compile a test program, you will likely get the message saying libsasl.dll is missing. You will need to download this file and put it in the same directory as your build.
I used 7-Zip to extract libsasl.dll from OpenLDAP for Windows. OpenLDAP for Windows
This is the result of my test code from above:
A lot of these instructions are out of date because they recommend the win32-ssl-devel-msvc package for curl, which no longer exists.
The following instructions allow you to build libcurl using only:
Visual Studio 2013
curl generic source tarball (tested on curl 7.44.0).
A. Build libcurl static library
Download the latest curl generic source from: http://curl.haxx.se/latest.cgi?curl=tar.gz
Extract the source to a local directory (we'll be using C:\libcurl)
Open a command prompt
"C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin\vcvars32.bat" To initialize your VC environment variables (adjust your VS 2013 installation directory as needed)
cd C:\libcurl\winbuild
nmake /f Makefile.vc mode=static VC=12
The build should appear in C:\libcurl\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl
B. Link Against libcurl in Visual Studio
In Visual Studio, right click your project in Solution Explorer, then click "Properties"
Configuration Properties > C/C++ > General > Additional Include Directories: add C:\libcurl\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\include
Configuration Properties > C/C++ > Preprocessor > Preprocessor Definitions: add CURL_STATICLIB
Configuration Properties > Linker > General > Additional Library Directories: add C:\libcurl\builds\libcurl-vc12-x86-release-static-ipv6-sspi-winssl\lib
Configuration Properties > Linker > Input > Additional Dependencies: add libcurl_a.lib
C. Call libcurl from Your Project
The following sample shows a call to libcurl:
#include "stdafx.h"
#include <curl/curl.h>
void main(int argc, char* argv[])
{
CURL *curl = curl_easy_init();
if (curl) printf("curl_easy_init() succeeded!\n");
else fprintf(stderr, "Error calling curl_easy_init().\n");
}
I would say that in a comment, but I am lacking in points.
You don't have to copy any .dll into your program run catalog.
Go to Project | Properties | Configuration Properties and in line Envrionment write: PATH=$(ExecutablePath)$(LocalDebuggerEnvironment).
From now on, all .dlls from any catalog you mention in Project|Project Properties|VC++ Directories|Binary should be usable without copying them.
The rest is exactly as you written.
The easiest way to do this that I found is first make sure that nuget is installed.
http://www.nuget.org/
Then create your project.
Then go to http://www.nuget.org/packages/curl/ and follow the instructions which is to go the package manager console and type PM> Install-Package curl
If you then look for the packages directory in your project directory, you will find the include files and the library files. Note that there is a version for Visual Studio 110, not 120, but because libcurl is a C library you can use it with Visual Studio 2013. Make sure the include directory and lib directory are specified under the Visual C++ directories in project properties.
Make sure you have the following files as addition input to the linker
libcurl.lib;libeay32.lib;ssleay32.lib;Ws2_32.lib;libssh2.lib;zlib.lib;wldap32.lib;
Another way to use curl/libcurl is build with CMake v2.8.12+ (assuming that git is already installed on your computer)
Open cmd window and change dir to appropriate folder
git clone https://github.com/bagder/curl.git
mkdir msbuild
cd msbuild
cmake ..\curl -G"Visual Studio 12 Win64" -DCMAKE_INSTALL_PREFIX=C:\curl.vc12 -DCURL_STATICLIB=ON
< ... lots of output here ... >
Open generated CURL.sln in Visual studio and build it.
CMake options I use in example
-G selects build generator. In our case Visual Studio 2013 64 bit target
-DCMAKE_INSTALL_PREFIX - provides root folder where targets should be installed
-DCURL_STATICLIB=ON - generates build for static library
After building install target, your will find bin/include/lib folders in C:\curl.vc12
Provide those path to your solution and build your code with curl lib.
I tried to do it from scratch with VS2012 (I don't have 2013) and it works perfectly.
I downloaded version 7.19.3 from http://curl.haxx.se/latest.cgi?curl=win32-ssl-devel-msvc because it's the only available version for VS.
I added the include directory, not the curl directory as he says in the tutorial.
I compiled a small toy project without any problem.
So, I'm not sure what your problem is, but:
Make sure you download the right archive.
Try to put the cURL folder on a path without space.
If you know someone who use VS2012 or older, try your code with the same include and lib and see if it works.
Paste a minimal working example of your code so I can test it.
This is a bit late, but for those who still have problems, this method worked best for me:
Add VS to the system PATH:
For example: C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\bin.
Download current curl-X.zip from http://curl.haxx.se/download.html and unzip.
Open command line at curl-X/winbuild.
Call vcvars32.bat.
Call nmake /f Makefile.vc mode=static VC=12.
Goto curl-X/builds/libcurl-XXX.
There you find the includes and a libcurl_a.lib.
This lib works fine for me.
Remember to define -DCURL_STATICLIB when you compile your code with this lib.
For Visual Studio 2017, the steps in link worked for me. In case the link expires or specifically for those who download the libcurl zip file instead of cloning from GitHub, I will note down the steps here.
Set environment variables with “C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat” x64. If the command is successful, you will see a message that says Environment initialized for 'x64'
Download and extract the compressed libcurl file from download libcurl. I used the .zip file.
cd into winbuild directory inside the extracted libcurl folder.
Run nmake /f Makefile.vc mode=dll MACHINE=x64 to build. For more information on build options, please refer to BUILD.WINDOWS text file in winbuild folder.
Go up one directory level and cd into builds folder to find the compiled files.
All the best!
The problem is that the targets for the default VS2013 platform tools are not set in the NuGet packages. This is why it works in VS2012 but not VS2013. I manually created replacement targets files. Instructions and download:
https://github.com/evoskuil/curl-nuget-targets
Download the curl v7.37.0 source code and use the Visual Studio project files provided.
I've spent the last few weeks polishing my own personal project files, that were based off the original VC6 files, and adding them to the repository.
.dsw / .dsp (VC6), .sln / .vcproj (VC7, VC7.1, VC8 and VC9 as well as .sln / .vcxproj (VC10, VC11 and VC12) files are provided for both DLL and Static Library builds with support for OpenSSL and Windows SSPI / SChannel in both Win32 and x64 configurations.
I found an easy way to get it work in VC++ using the latest package. I basically followed the steps in Using libcurl in Visual Studio. The libcurl and VC++ are very old in the instruction.
First download the ZIP file on download page https://curl.haxx.se/download.html The ZIP package is https://curl.haxx.se/download/curl-7.50.1.zip
Go to projects-> Windows\VC10 (or your version of VC)\lib\libcurl.sln, open the project in VC++.
Build the project in DLL Release. DLL debug doesn't work on my VC++.
Go to build\Win32\VC10\DLL Release, you can find the lib and dll files generated from previous step.
Create a folder new, with include and lib folders. Copy the libcurb.dll and libcurb.lib whatever is in the DLL Release folder to the new\lib. Copy everything in curl-7.50.1\include to new\include folder.
C++ Properties -> Configuration Properties -> VC++ Directories, add new\include to Include Directories, new\lib to Library Directories; add new\lib to Linker -> General -> Additional Library Directories, add libcurl.lib to Linker -> Input -> Additional Dependencies
It seems that I have to put the dll file under the same folder with executable file.
It should work.

How can I build a program using c++ driver of mongodb?

Please tell me how to build a program using c++ driver of mongodb.
No flames about my bad English.
My Environment
Windows7 64bit
Visual Studio Ultimate 2012 (x64 Release target project)
I performed the following steps.
I installed Ptython 2.7.2, Python for Windows extensions and Scons 2.3.0.
I installed boost 1.54.0. I perfomed 'boostrap' and 'b2 -a --build-type=complete --address-model=64 --link=static --runtime-link=static'
I download mongodb-linux-x86_64-v2.4-latest.tgz.
I added the following texts to SConstruct.
env.Append(CPPPATH=['C:\\boost\\boost_1_54_0'])
env.Append(LIBPATH=['C:\\boost\\boost_1_54_0\\stage\\lib'])
env.Append(CPPDEFINES=["_UNICODE"])
env.Append(CPPDEFINES=["UNICODE"])
I performed 'scons mongoclient'.
I made a project of Visual Studio C++.
I set 'Release' and 'x64' in the project.
In Property pages/Configuration Properties/C C++/General/Additional Include Directories, I set 'C:\boost\boost_1_54_0' and 'C:\mongo\mongo-cxx-driver-v2.4\src'.
In Property pages/Configuration Properties/Linker/General/Additional Library Directories,
I set 'C:\boost\boost_1_54_0\stage\lib' and 'C:\mongo\mongo-cxx-driver-v2.4'.
In Property pages/Configuration Properties/Linker/Input/Additional Dependences, I set 'mongoclient.lib','ws2_32.lib' and 'psapi.lib'.
In Property pages/Configuration Properties/Linker/Input/Ignore Specific Default Libraries, I set 'msvcprt.lib' and 'LIBCMT.lib'.
In Property pages/Configuration Properties/C C++/Preprosessor/Preprocessor Definitions, I set '_CRT_SECURE_NO_WARNINGS'.
In Property pages/Configuration Properties/C C++/Code Generation/Runtime Library, I set 'Multi-threaded (/MT)'.
I made a program using the driver. However, the build solution of the program has failed.
1>mongoclient.lib(stringutils.obj) : error LNK2001: unresolved external symbol __security_check_cookie
1>mongoclient.lib(initializer_dependency_graph.obj) : error LNK2001: unresolved external symbol __security_check_cookie
1>mongoclient.lib(initializer.obj) : error LNK2001: unresolved external symbol __security_check_cookie
....
fatal error LNK1120: 154 unresolved externals
If would help me if you pointed out anything strange about the steps.
Thank you.
How to build MongoDB C++ driver
This solution succeeded on a machine with the following characteristics:
Windows XP SP3 32-bit
Visual Studio Express 2010 (VC 10)
I used D:\MongoDBcplusplusClient as a working directory (I installed there all the prerequisites).
Process:
Step 1
Download MongoDB C++ driver:
https://github.com/mongodb/mongo-cxx-driver
You can make a clone using Git or download it as a .zip file (I did the second).You will get a file like mongo-cxx-driver-legacy.zip. Extract it to the folder mongo-cxx-driver-legacy inside your working directory.
Step 2
Download Boost prebuilt windows binaries. ATTENTION!!! You should use a specific version of Boost. In my case version 1.52 did the trick. You can download it from here:
http://boost.teeks99.com/
I downloaded the boost_1_52_0-vc32-bin.exe self-extracting exe. Put it on your working directory and run it. It will create a folder (something like lib32) that will contain the boost binaries (.lib and .dll files)
Step 3
Download Boost source code (.h files). Of course these should be from the same version as in Step 2. I downloaded them from here:
http://sourceforge.net/projects/boost/files/boost/1.52.0/
You will get a file boost_1_52_0.zip which you can extract at boost_1_52_0 folder.
Step 4
Download Python. In this example I downloaded version 2.7.9 and specifically the Windows x86 MSI installer from here:
https://www.python.org/downloads/release/python-279/
Step 5
Download Scons from here:
http://www.scons.org/download.php
I downloaded the Windows installer (scons-2.3.4-setup.exe) and installed Scons at the Python directory (in my case C:\Python27).
Step 6
Download msinttypes from here:
https://code.google.com/p/msinttypes/
(You should include these header files to the project that uses the driver)
Step 7
Go to Start->Run… and in the Run box write cmd. In the opened command prompt window navigate to the folder at which you extracted mongo driver at Step 1. In my case I did:
cd D:\ D:\MongoDBcplusplusClient\mongo-cxx-driver-legacy\mongo-cxx-driver-legacy
Step 8
Build the driver using Scons. In the directory you navigated at Step 7 write:
scons
--prefix=D:\MongoDBcplusplusClient\mongo-cxx-driver-legacy\mongo-cxx-driver-legacy
--cpppath=D:\MongoDBcplusplusClient\boost_1_52_0\boost_1_52_0
--libpath= D:\MongoDBcplusplusClient\lib32
--win-version-min=xpsp3 install
and hit Enter.
The --prefix flag specifies the target directory at which the .lib file of the driver will be created, --cpppath specifies the folder at which the Boost header files are located and the --libpath the path to Boost .lib files. Of course you should change the path to yours. A file named libmongoclient-s.lib will be created at the --prefix/lib path.
If you want to build the driver with debugging enabled you should use the following command:
scons
--prefix=D:\MongoDBcplusplusClient\mongo-cxx-driver-legacy\mongo-cxx-driver-legacy
--cpppath=D:\MongoDBcplusplusClient\boost_1_52_0\boost_1_52_0
--libpath= D:\MongoDBcplusplusClient\lib32
--win-version-min=xpsp3
--dbg=on install
A file named libmongoclient-sgd.lib will be created at the --prefix/lib path.
Step 9
At Windows Explorer navigate to the folder at which MongoDB C++ driver is installed, go into the subfolder lib (in my case this was D:\MongoDBcplusplusClient\mongo-cxx-driver-legacy\mongo-cxx-driver-legacy\lib) and rename the file libmongoclient-s.lib to mongoclient.lib and the libmongoclient-sgd.lib to mongoclient-gd.lib.
Step 10
Open Visual Studio 2010 Express and open the project at which you want to use the MongoDB C++ driver. You should specify the dependencies. Right click on project’s name at solution explorer (left column) and hit Properties.
Go to C/C++ → General and at Additional Include Directories add:
a) Boost header files directory (in my case D:\MongoDBcplusplusClient\boost_1_52_0\boost_1_52_0)
b) MongoDB C++ driver header files directory (in my case
D:\MongoDBcplusplusClient\mongo-cxx-driver-legacy\mongo-cxx-driver
legacy\include)
c) Cstdint types header files directory (in my case
:\MongoDBcplusplusClient\msinttypes-r26 )
Step 11
Go to Linker → General and at Additional Library Directories add:
a) Boost .lib files directory (in my case D:\MongoDBcplusplusClient\lib32)
b) MongoDB C++ driver .lib files directory (in my case D:\MongoDBcplusplusClient\mongo-cxx-driver-legacy\mongo-cxx-driver-legacy\lib)
After these steps the project that uses the driver will be successfully built both in release and debug configurations.
Simple solution use vcpkg.
Download vcpkg follow the instructions as mentioned on git.
https://github.com/Microsoft/vcpkg
Step 1
C:\vcpkg>.\vcpkg search mongodb
you will see something like this
mongo-c-driver 1.6.2-1 Client library written in C for MongoDB.
mongo-cxx-driver 3.1.1-1 MongoDB C++ Driver.
Step 2
C:\.\vcpkg search mongodb install mongo-cxx-driver
then grab cup of coffee ....
Step 3
C:\vcpkg>.\vcpkg integrate install
Done..
Note
Prerequisites:
Windows 10, 8.1, or 7
Visual Studio 2017 or Visual Studio 2015 Update 3
simply import
#include <cstdint>
#include <iostream>
#include <vector>
#include <bsoncxx/json.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/stdx.hpp>
#include <mongocxx/uri.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;