How can I deal with dll and lib files for connecting MariaDB to C++ Application?


I am trying to work on the project which is to connect MariaDB with C++ application. I referred to the URL: This URL is quite a good source to connect MariaDB with C++. However, it doesn't describe how to deal with the lib file and dll file. When I installed the MariaDB connector/C++ via MSI, it gave me several files: conncpp.hpp, mariadbcpp.dll, mariadbcpp.lib, etc.

I tried to include mariadb/conncpp.hpp by setting the path C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.28.29910\include and I did same with the lib file. Also, I went to the properties and set the linkers for the lib file. Here is the code that I am planning to execute:

// Includes
#include <iostream>
#include <mariadb/conncpp.hpp>

// Main Process
int main(int argc, char** argv)
        // Instantiate Driver
        sql::Driver* driver = sql::mariadb::get_driver_instance();
    // Configure Connection
    // The URL or TCP connection string format is
    // ``jdbc:mariadb://host:port/database``.
    sql::SQLString url("jdbc:mariadb://");

    // Use a properties map for the user name and password
    sql::Properties properties({
          {"user", "db_user"},
          {"password", "db_user_password"}

    // Establish Connection
    // Use a smart pointer for extra safety
    std::unique_ptr<sql::Connection> conn(driver->connect(url, properties));

    // Use Connection
    // ...

    // Close Connection

// Catch Exceptions
catch (sql::SQLException& e)
    std::cerr << "Error Connecting to MariaDB Platform: "
        << e.what() << std::endl;

    // Exit (Failed)
    return 1;

// Exit (Success)
return 0;

But whenever I compile and execute the code, it says Unhandled exception(0x00007FF918058D25(mariadbcpp.dll), MariaDB_Connection.exe): 0xC0000005:Access violation reading location 0xFFFFFFFFFFFFFFFF at the line of std::unique_ptr<sql::Connection> conn(driver->connect(url, properties));.

Could you tell me how to solve this problem?

asked on Stack Overflow Apr 26, 2021 by sol • edited Apr 26, 2021 by sol

1 Answer


You've hit the deficiency in the C++ connector API. Or call it a bug. It's Windows specific. Debug and release versions of STL objects may have different layout. Switching build to release configuration should help. But some issues are still possible depending on VS version used. As a workaround you could also try to use other connect method, i.e. std::unique_ptr<sql::Connection> conn(driver->connect(url, "db_user", "db_user_password")); since it doesn't rely on Properties map, that causes the issue here.

answered on Stack Overflow May 6, 2021 by Lawrin Novitsky • edited May 7, 2021 by Lawrin Novitsky

User contributions licensed under CC BY-SA 3.0