Skip to content

[Linux] Build the CPP SMTPClient library

Jeremy Dumais edited this page Apr 19, 2025 · 2 revisions

Build the CPP-SMTPClient-library on Linux

1 - Getting OpenSSL dependency

In order to build the CPP-SMTPClient-Library, you will need the OpenSSL development package.

Ubuntu

On Ubuntu, here is how you can install OpenSSL development package:

apt-get install libssl-dev

2 - Getting the CPP-SMTP-Library source code

Navigate to the folder where you want the solution to be and then enter the following command:

git clone https://github.com/jeremydumais/CPP-SMTPClient-library.git

3 - Preparing the build folder

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

cd CPP-SMTPClient-library
mkdir build
cd build

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

cmake ..

Debug mode

cmake -DCMAKE_BUILD_TYPE=Debug ..

Static library

By default the library is build as dynamic, meaning the library will be stored in a separate file (.so file extension).

If you want to build the library as static you need to turn off the CMake flag BUILD_SHARED_LIBS.

cmake -DBUILD_SHARED_LIBS=OFF ..

Including unit tests

The library unit tests will not be built by default. To include them just add the BUILD_TESTING=ON to the configure command.

cmake -DBUILD_TESTING=ON ..

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.

-- The C compiler identification is GNU 11.4.0
-- The CXX compiler identification is GNU 11.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenSSL: /usr/lib/x86_64-linux-gnu/libcrypto.so (found version "3.0.2")
-- clang-tidy not found.
-- Performing Test HAS_CXX14_FLAG
-- Performing Test HAS_CXX14_FLAG - Success
-- Performing Test HAS_CXX17_FLAG
-- Performing Test HAS_CXX17_FLAG - Success
-- Performing Test HAS_CXX20_FLAG
-- Performing Test HAS_CXX20_FLAG - Success
-- WARNING: building release version!
-- Configuring done
-- Generating done
-- Build files have been written to: /home/jed/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_INCLUDE_DIRECTORY=/usr/include -DOPENSSL_LIBRARY_DIRECTORY=/usr/lib/x86_64-linux-gnu -DOPENSSL_CRYPTO_LIBRARY=crypto -DOPENSSL_SSL_LIBRARY=ssl ..

5 - Building the library

Release mode

cmake --build . --config Release

Debug mode

cmake --build . --config Debug

The resulting library libsmtpclient.a should be created in that current folder (build).

6 - Installing the library

From the build folder run the following command :

sudo make install

The next step is to consume the library from your own solution. Follow this guide to for more information: How to consume the CPP-SMTP-Library in your application

If you want to uninstall the library, simply run the following command:

sudo make uninstall