错误LNK2001:未解析的外部符号_PQconnectdb。 MFC应用程序

时间:2013-07-12 09:53:13

标签: c++ mfc linker linker-errors unsatisfiedlinkerror

我有以下文件和错误,如下所述:
1- Connection.cpp

#include "iostream"
#include "stdafx.h"
#include "Connection.h"
#include <libpq-fe.h>
using namespace std;

Connection::Connection()
{

}

PGconn *Connection::getConnection()
{
        const char *connStr = "dbname=Fidelity user=postgres password=home hostaddr=127.0.0.1 port=5432";
    PGconn* conn;
    conn = PQconnectdb(connStr);
   /* if(PQstatus(conn) != CONNECTION_OK)
          {
            cout << "\nConnection Failed.";
            PQfinish(conn);
          }
    else
          {
            cout << "\nConnection Successful\n\n";
          }*/
    return conn;
}

2-主文件:

#include "stdafx.h"
#include "DataCorroborationDLL.h"
#include "iostream"
#include "conio.h"
#include "Connection.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// The one and only application object

CWinApp theApp;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;

HMODULE hModule = ::GetModuleHandle(NULL);

if (hModule != NULL)
{
    // initialize MFC and print and error on failure
    if (!AfxWinInit(hModule, NULL, ::GetCommandLine(), 0))
    {
        // TODO: change error code to suit your needs
        _tprintf(_T("Fatal Error: MFC initialization failed\n"));
        nRetCode = 1;
    }
    else
    {
        cout << "Hello world";
                    Connection con;
        con.getConnection();
        cout <<getch();
    }
}
else
{
    // TODO: change error code to suit your needs
    _tprintf(_T("Fatal Error: GetModuleHandle failed\n"));
    nRetCode = 1;
}

return nRetCode;
}

我已经包含了&#34;包含目录&#34;安装它的postgresql,它包括目录和lib目录。它识别postgres命令,但不是全部。现在当我编译时,我收到此错误:

Connection.obj:错误LNK2001:未解析的外部符号_PQconnectdb
1&gt; C:\ Users \ Irfan \ Desktop \ IGD \ DataCorroborationDLL \ Release \ Tests.exe:致命错误
LNK1120:1未解析的外部

0 个答案:

没有答案