0
votes

Im using visual studio 2012 Ultimate and PostgreSQL 9.2 64 bit. I set up a completely new project with the following settings:

Additional includes folder: "C:\Program Files\PostgreSQL\9.2\include\"

Additional libs folder: "C:\Program Files\PostgreSQL\9.2\lib\"

Im linking against "libpq.lib".

My problem looks like that:

#include <iostream>
using namespace std;

#include <libpq-fe.h>

int main() {

    PGconn *psql = PQconnectdb("hostaddr = '127.0.0.1' port = '' dbname = 'fwaggle' user = 'fwaggle' password = 'password' connect_timeout = '10'");
    /* init connection */
    if (!psql) {

    }

    std::cin.get();
    return 0;
}

Result: "error LNK2019: Verweis auf nicht aufgelöstes externes Symbol "_PQconnectdb" in Funktion "_main". I cant get rid of this linker error, what am I doing wrong?

2
For those who cannot guess what the error message says: Reference to unresolved external symbol "_PQconnectdb" in function "_main". - Oswald

2 Answers

2
votes

Have a look at this link: http://www.askyb.com/cpp/c-postgresql-example/

It suggests that you have to set the Additional Dependencies as well as the Additional Includes and Lib folders.

Failing that, double check the name of the method you're trying to call and double-check the paths in the Additional Includes and Lib settings; copy and paste them from Explorer to make certain.

You might also want to use depends.exe to check that the DLL is actually exporting the method you're after.

2
votes

Ok i figured out what was going on:

As written I installed PostgreSQL 64 bit but i tried to compile and link a 32 bit project against the 64-bit libpg from PostgreSQL. After changing from WIN32 to x64 linking was successfull.