1

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?

Anonymous
  • 4,617
  • 9
  • 48
  • 61
  • 3
    For those who cannot guess what the error message says: *Reference to unresolved external symbol "_PQconnectdb" in function "_main"*. – Oswald Apr 04 '13 at 11:02

2 Answers2

2

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.

Mike P
  • 742
  • 11
  • 26
  • Just wanted to point out I've hit the same problem as the question, and setting libpq.dll as an additional dep worked for me after copying libpq.dll and libint.dll to the local dir! – user3791372 Aug 06 '14 at 07:35
2

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.

Anonymous
  • 4,617
  • 9
  • 48
  • 61