-
Notifications
You must be signed in to change notification settings - Fork 21
Build the CPP SMTPClient library on Windows
To get OpenSSL in order to build the CPP-SMTPClient-Library you can use one of the following way (Chocolatey or OpenSSL Downloaded Binary).
You can install Chocolatey on your system following the guide here
Once installed, you need to start a command prompt as an admin and type the following command:
choco install openssl
If you want the 32 bits version use the following command:
choco install --forceX86 openssl
The resulting files will then be in C:\Program Files\OpenSSL-Win64 or C:\Program Files (x86)\OpenSSL-Win32 depending on the version you took.
I strongly suggest to create an environment variable OPENSSL_ROOT_DIR that point to your installation folder. (Ex: C:\Program Files\OpenSSL-Win64)
It is recommended to use the command RefreshEnv to make sure your environment variables are refreshed.
You can download one of the prebuilt binary here.
Once downloaded and extracted on your hard drive, I strongly suggest to create an environment variable OPENSSL_ROOT_DIR that point to your installation folder. (Ex: C:\openssl\x64)
It is recommended to close and reopen your Windows session to make sure that your environment variables are refreshed.
When building CPP-SMTPClient-library as a standalone project, the typical workflow starts with:
cd "installation folder"
mkdir build
cd build
The next step is to configure and generate project files. Enter one of the following command depending on the version and the mode you want:
cmake ..
cmake -DCMAKE_GENERATOR_PLATFORM=Win32 -DCMAKE_BUILD_TYPE=Release -T host=x86 ..
cmake -DCMAKE_BUILD_TYPE=Debug ..
cmake -DCMAKE_GENERATOR_PLATFORM=Win32 -DCMAKE_BUILD_TYPE=Debug -T host=x86 ..
During the configuration and generation phase you will see if CMake was able to find OpenSSL or not.
See below an example of resulting configuration and generation. The OpenSSL important lines are in bold.
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.19045.
-- The C compiler identification is MSVC 19.26.28806.0
-- The CXX compiler identification is MSVC 19.26.28806.0
...
-- Found OpenSSL: optimized;C:/Program Files/OpenSSL-Win64/lib/VC/libcrypto64MD.lib;debug;C:/Program Files/OpenSSL-Win64/lib/VC/libcrypto64MDd.lib (found version "1.1.1s")
-- WARNING: building release version!
-- No OPENSSL_ROOT_DIR variable provided so searching for the OPENSSL_ROOT_DIR environment variable...
-- Found OPENSSL_ROOT_DIR=C:\Program Files\OpenSSL-Win64 as an environment variable.
-- Will use OpenSSL include directory C:\Program Files\OpenSSL-Win64/include
-- Will use OpenSSL lib directory C:\Program Files\OpenSSL-Win64/lib}
-- Will use OpenSSL libraries files optimized;C:/Program Files/OpenSSL-Win64/lib/VC/libcrypto64MD.lib;debug;C:/Program Files/OpenSSL-Win64/lib/VC/libcrypto64MDd.lib optimized;C:/Program Files/OpenSSL-Win64/lib/VC/libssl64MD.lib;debug;C:/Program Files/OpenSSL-Win64/lib/VC/libssl64MDd.lib
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/jed/Source/Repos/CPP-SMTPClient-library/build
If for some reasons OpenSSL was not found correctly, you can provide your folders and library files via the following CMake variables:
- OPENSSL_ROOT_DIR
- OPENSSL_INCLUDE_DIRECTORY
- OPENSSL_LIBRARY_DIRECTORY
- OPENSSL_CRYPTO_LIBRARY
- OPENSSL_SSL_LIBRARY
Ex:
cmake -DOPENSSL_ROOT_DIR=C:\openssl\x64 -DOPENSSL_INCLUDE_DIRECTORY=C:\openssl\x64\include -DOPENSSL_LIBRARY_DIRECTORY=C:\openssl\x64\lib -DOPENSSL_CRYPTO_LIBRARY=crypto -DOPENSSL_SSL_LIBRARY=ssl ..
cmake --build . --config Release
cmake --build . --config Release
cmake --build .
cmake --build .
The resulting library smtpclient.dll should be created in the folder build\Debug or build\Release depending on the build mode you have chosen.
You can also build the project using Visual Studio, just click File -> Open -> Folder... and the select the folder where you have downloaded CPP-SMTPClient-library. You can then build the project using Visual Studio.