Skip to content

Build the CPP SMTPClient library on Windows

Jeremy Dumais edited this page Dec 31, 2022 · 3 revisions

Build the CPP-SMTPClient-library on Windows

1 - Getting OpenSSL dependency

To get OpenSSL in order to build the CPP-SMTPClient-Library you can use one of the following way (Chocolatey or OpenSSL Downloaded Binary).

Chocolatey

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.

OpenSSL Binary Distributions for Microsoft Windows

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.

2 - Preparing the build folder

When building CPP-SMTPClient-library as a standalone project, the typical workflow starts with:

    cd "installation folder"
    mkdir build
    cd build

3 - Configuration and generation

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:

Release mode

64 bits (x64)

    cmake ..

32 bits (x86)

    cmake -DCMAKE_GENERATOR_PLATFORM=Win32 -DCMAKE_BUILD_TYPE=Release -T host=x86 ..

Debug mode

64 bits (x64)

    cmake -DCMAKE_BUILD_TYPE=Debug ..

32 bits (x86)

    cmake -DCMAKE_GENERATOR_PLATFORM=Win32 -DCMAKE_BUILD_TYPE=Debug -T host=x86 ..

Troubleshooting OpenSSL folders and library files

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 ..

4 - Building the library

Release mode

64 bits (x64)

    cmake --build . --config Release

32 bits (x86)

    cmake --build . --config Release

Debug mode

64 bits (x64)

    cmake --build .

32 bits (x86)

    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.