Linker errors while building c++ app which use pqxx library

70 Views Asked by At

i encounter problems while building an c++ app with pqxx library. I installed this library with c++ package manager called vcpkg. Other libraries like boost or curl work but pqxx not. I there some solution for that problem? I am using visual studio 2022 on windows 11 and project is configure to latest c++.

Here is error:

1>ConsoleApplication4.obj : error LNK2019: unresolved external symbol "public: __cdecl PgConnector::PgConnector(void)" (??0PgConnector@@QEAA@XZ) referenced in function "bool __cdecl tryUpdateEmailAccounts(int,class std::vector<class PgConnector *,class std::allocator<class PgConnector *> >)" (?tryUpdateEmailAccounts@@YA_NHV?$vector@PEAVPgConnector@@V?$allocator@PEAVPgConnector@@@std@@@std@@@Z)
1>ConsoleApplication4.obj : error LNK2019: unresolved external symbol "public: void __cdecl PgConnector::setCurrentDatabase(class Database)" (?setCurrentDatabase@PgConnector@@QEAAXVDatabase@@@Z) referenced in function "void __cdecl restartMailer(class PgConnector *,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?restartMailer@@YAXPEAVPgConnector@@HV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>ConsoleApplication4.obj : error LNK2019: unresolved external symbol "public: void __cdecl PgConnector::setConnectionError(int)" (?setConnectionError@PgConnector@@QEAAXH@Z) referenced in function main
1>ConsoleApplication4.obj : error LNK2019: unresolved external symbol "public: bool __cdecl PgConnector::isOpen(void)" (?isOpen@PgConnector@@QEAA_NXZ) referenced in function main
1>ConsoleApplication4.obj : error LNK2019: unresolved external symbol "public: class Database __cdecl PgConnector::getDatabaseData(class boost::property_tree::basic_ptree<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > >,int)" (?getDatabaseData@PgConnector@@QEAA?AVDatabase@@V?$basic_ptree@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@U?$less@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@property_tree@boost@@H@Z) referenced in function main
1>ConsoleApplication4.obj : error LNK2019: unresolved external symbol "public: class pqxx::result __cdecl PgConnector::executeQuery(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?executeQuery@PgConnector@@QEAA?AVresult@pqxx@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "bool __cdecl checkDbAccountsUpdateRequired(int,class PgConnector *,class std::map<int,struct EmailAccount,struct std::less<int>,class std::allocator<struct std::pair<int const ,struct EmailAccount> > >)" (?checkDbAccountsUpdateRequired@@YA_NHPEAVPgConnector@@V?$map@HUEmailAccount@@U?$less@H@std@@V?$allocator@U?$pair@$$CBHUEmailAccount@@@std@@@3@@std@@@Z)
1>ConsoleApplication4.obj : error LNK2019: unresolved external symbol "public: int __cdecl PgConnector::performQuery(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?performQuery@PgConnector@@QEAAHV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "void __cdecl restartMailer(class PgConnector *,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?restartMailer@@YAXPEAVPgConnector@@HV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>ConsoleApplication4.obj : error LNK2019: unresolved external symbol "public: void __cdecl PgConnector::dispose(void)" (?dispose@PgConnector@@QEAAXXZ) referenced in function "bool __cdecl tryUpdateEmailAccounts(int,class std::vector<class PgConnector *,class std::allocator<class PgConnector *> >)" (?tryUpdateEmailAccounts@@YA_NHV?$vector@PEAVPgConnector@@V?$allocator@PEAVPgConnector@@@std@@@std@@@Z)
1>ConsoleApplication4.obj : error LNK2019: unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl DataHelper::dateToString(__int64,char const *)" (?dateToString@DataHelper@@SA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@_JPEBD@Z) referenced in function "bool __cdecl checkDbAccountsUpdateRequired(int,class PgConnector *,class std::map<int,struct EmailAccount,struct std::less<int>,class std::allocator<struct std::pair<int const ,struct EmailAccount> > >)" (?checkDbAccountsUpdateRequired@@YA_NHPEAVPgConnector@@V?$map@HUEmailAccount@@U?$less@H@std@@V?$allocator@U?$pair@$$CBHUEmailAccount@@@std@@@3@@std@@@Z)
1>ConsoleApplication4.obj : error LNK2019: unresolved external symbol "public: static __int64 __cdecl DataHelper::stringToDate(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?stringToDate@DataHelper@@SA_JV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@0@Z) referenced in function "int __cdecl loadAccounts(int,class PgConnector *)" (?loadAccounts@@YAHHPEAVPgConnector@@@Z)
1>ConsoleApplication4.obj : error LNK2019: unresolved external symbol "public: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl DataHelper::nullStringToEmpty(char const *)" (?nullStringToEmpty@DataHelper@@SA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PEBD@Z) referenced in function "struct EmailAccount * __cdecl loadAccount(int,class pqxx::const_result_iterator)" (?loadAccount@@YAPEAUEmailAccount@@HVconst_result_iterator@pqxx@@@Z)
1>ConsoleApplication4.obj : error LNK2019: unresolved external symbol "public: static bool __cdecl DataHelper::checkSystemVersion(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,int)" (?checkSystemVersion@DataHelper@@SA_NV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z) referenced in function main
1>ConsoleApplication4.obj : error LNK2019: unresolved external symbol "public: __cdecl curlWrapper::curlWrapper(void)" (??0curlWrapper@@QEAA@XZ) referenced in function "public: __cdecl EmailAccount::EmailAccount(struct EmailAccount const &)" (??0EmailAccount@@QEAA@AEBU0@@Z)
1>ConsoleApplication4.obj : error LNK2019: unresolved external symbol "public: static void __cdecl Settings::loadProperties(class boost::property_tree::basic_ptree<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,struct std::less<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > >)" (?loadProperties@Settings@@SAXV?$basic_ptree@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V12@U?$less@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@property_tree@boost@@@Z) referenced in function main
1>ConsoleApplication4.obj : error LNK2019: unresolved external symbol "public: static void __cdecl ImapClient::emailAccountMainActions(class PgConnector *,int,class curlWrapper *,int,bool)" (?emailAccountMainActions@ImapClient@@SAXPEAVPgConnector@@HPEAVcurlWrapper@@H_N@Z) referenced in function main
1>ConsoleApplication4.obj : error LNK2019: unresolved external symbol "public: static void __cdecl MailerLogger::getLogger(void)" (?getLogger@MailerLogger@@SAXXZ) referenced in function main
1>ConsoleApplication4.obj : error LNK2019: unresolved external symbol "public: static void __cdecl MailerLogger::debug(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?debug@MailerLogger@@SAXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "bool __cdecl checkDbAccountsUpdateRequired(int,class PgConnector *,class std::map<int,struct EmailAccount,struct std::less<int>,class std::allocator<struct std::pair<int const ,struct EmailAccount> > >)" (?checkDbAccountsUpdateRequired@@YA_NHPEAVPgConnector@@V?$map@HUEmailAccount@@U?$less@H@std@@V?$allocator@U?$pair@$$CBHUEmailAccount@@@std@@@3@@std@@@Z)
1>ConsoleApplication4.obj : error LNK2019: unresolved external symbol "public: static void __cdecl MailerLogger::info(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?info@MailerLogger@@SAXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function "void __cdecl restartMailer(class PgConnector *,int,class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?restartMailer@@YAXPEAVPgConnector@@HV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z)
1>ConsoleApplication4.obj : error LNK2019: unresolved external symbol "public: static void __cdecl MailerLogger::error(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?error@MailerLogger@@SAXV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z) referenced in function main
1>C:\Users\Marketing\source\repos\ConsoleApplication4\x64\Debug\ConsoleApplication4.exe : fatal error LNK1120: 19 unresolved externals

ps. Before using vcpkg i manually installed and added libraries to my project and same things was happening.

here is code of pgConnector:

#include <string>
#include <pqxx/pqxx>
#include <boost/property_tree/ptree.hpp>

class Database
{
    public:
        std::string  host;
        int   port;
        std::string  db_name;
        std::string  username;
        std::string  password;
        int database_id;
};

class PgConnector {
    private:
        int current_database = -1;
        bool connection_error = false;
    public:
        Database database;
        pqxx::connection* pg_connection;
        PgConnector();
        void disconnect();
        bool getConnection(bool first);//pqxx::connection
        void setCurrentDatabase(Database database);
        void setConnectionError(int connection_state);
        int getCurrentDatabase();
        bool isOpen();
        Database getDatabaseData(boost::property_tree::basic_ptree<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::less<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > > database_section, int database_id);
        /* Execute query which return values*/
        pqxx::result executeQuery(std::string query);
        /* Execute query which don't return values*/
        int performQuery(std::string query);
        int performQuery(std::string query, std::vector<std::string> parameters);
        void dispose();
};

and imapClient

#pragma once
#include "curlWrapper.h"

class ImapClient {
    public:
        static curlWrapper curl_wrapper;
        static curlWrapper curl_wrapper_read;
        static curlWrapper curl_wrapper_delete;
        static void copyMessagesFromOutcome(PgConnector* pg_connector);
        static void getMailsHeaders(PgConnector* pg_connector, bool full_synch, int account_id);
        static void saveMessage(PgConnector* pg_connector, std::string query, bool has_new_message);
        static std::string buildSaveMessage(Message message,PgConnector* pg_connector, int account_id, int default_mail_type, bool mail_exist, std::string update_query_where);
        static void checkReadedMessages(PgConnector* pg_connector, int email_account_id);
        static void checkDeletedMessages(PgConnector* pg_connector, int email_account_id);
        static void updateAccountMessagesCounter(PgConnector* pg_connector);
        static void emailAccountMainActions(PgConnector* pg_connector, int email_account_id,curlWrapper* curl_wrapper, int curl_number, bool update_connection_data);
};

here is code using pgConnector:

bool tryUpdateEmailAccounts(int db_iteration_counter, std::vector<PgConnector*> pg_connectors)
{
    if (db_iteration_counter != 0) {
        return false;
    }

    bool dbs[2222] = { false };
    bool need_update = false;
    PgConnector* pg_conn = new PgConnector();

    for (auto& db : ObserverResult::email_accounts) {
        pg_conn->setCurrentDatabase(Settings::databases[db.first]);

        if (checkDbAccountsUpdateRequired(db.first, pg_conn, db.second)) {
            MailerLogger::info("Account update required for db: " + std::to_string(db.first));

            dbs[db.first] = true;
            need_update = true;
        }
    }

    if (!need_update) {
        pg_conn->dispose();
        delete pg_conn;
        return false;
    }

    int db_id = 0;

    MailerLogger::info("Account update required. Waiting for all threads...");
    std::time_t before_start = std::time(nullptr);

    while (ObserverResult::used_threads != 0) {
        if (before_start < std::time(nullptr) - (15 * 60)) { // jesli watki nie zostana zwolnione przez 15 minut - restart
            MailerLogger::debug("Break waiting for all threads, restart needed...");
            restart_needed = true;
            break;
        }

        MailerLogger::debug("Waiting for threads: " + std::to_string(ObserverResult::used_threads) + "...");
        ObserverResult::stopped_counter = -1;
        boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
    }

    all_accounts = 0;
    for (auto& db : ObserverResult::email_accounts) {
        db_id = db.first;
        pg_conn->setCurrentDatabase(Settings::databases[db_id]);

        if (restart_needed) {
            pg_conn->performQuery(mail_restart_query);
            continue;
        }

        if (!dbs[db_id]) {
            all_accounts += (ObserverResult::email_accounts[db_id].size() - 1);
            continue;
        }

        MailerLogger::debug("Refreshing accounts for db: " + std::to_string(db_id));

        ObserverResult::email_accounts[db_id].clear();

        loadSystemAccount(db_id, pg_conn);
        all_accounts += loadAccounts(db_id, pg_conn);
    }

    pg_conn->dispose();
    delete pg_conn;

    return true;
}

above function call:

unsigned int enabled_threads = Settings::enabled_threads;

unsigned int curl_wrapper_counter = 0;
std::vector<PgConnector*> pg_connectors = {};
std::vector<curlWrapper*> curl_wrappers = {};

pg_connectors.push_back(new PgConnector());

for (unsigned int i = 0; i < enabled_threads; i++)
{
    curl_wrappers.push_back(new curlWrapper());
    pg_connectors.push_back(new PgConnector());
}

int db_iteration_counter = 1

update_connection_data = tryUpdateEmailAccounts(db_iteration_counter, pg_connectors);

I never use that complicated c++ code before and i have to compile app just from code that i have. I am trying to compile it but, when i add all libraries this errors happens and i dont know what to do with it

0

There are 0 best solutions below