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?

1
  • 3
    For those who cannot guess what the error message says: Reference to unresolved external symbol "_PQconnectdb" in function "_main". Commented Apr 4, 2013 at 11:02

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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!
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.