Skip to content

USE_POSTGRESQL symbol not defined even if Postgres detected #2386

@daggilli

Description

@daggilli

I am installing Drogon with Postgres support. I have the development headers and libraries. CMake detects Postgres and sets pg_FOUND correctly. Postgres is enabled with option(USE_POSTGRESQL "Enable PostgreSQL" ON). However, the preprocessor symbol USE_POSTGRESQL is not set. Thus in DbClientManager::addDbClient() in orm_lib/src/DBClientManager.cc the code to add the Postgres connection configuration to the dbInfos_ vector is not compiled and the fatal error is produced at runtime instead.

To resolve the problem, I manually added the USE_POSTGRESQL definition to CMakeLists.txt around line 616:

if (pg_FOUND OR DROGON_FOUND_MYSQL OR DROGON_FOUND_SQLite3)
    if (pg_FOUND)
        message(STATUS "Enable PostgreSQL")
        option(USE_POSTGRESQL "Enable PostgreSQL" ON)
        add_definitions(-DUSE_POSTGRESQL)
    else (pg_FOUND)
        option(USE_POSTGRESQL "Disable PostgreSQL" OFF)
    endif (pg_FOUND)

I confirmed the absence of the USE_POSTGRESQL symbol was the issue by adding static_assert and assert macros to the Drogon source code, rebuilding, and observing that compilation and runtime failures occurred in the expected places.

Once I added the definition directly to CMakeLists.txt I was able to connect to my Postgres server without any further issues.

I am using Ubuntu 22.04 with gcc 15 and CMake 4.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions