0

我有以下文件,错误描述如下:
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;
}

我已经包含了安装它的 postgresql 的“包含目录”,它包括目录和 lib 目录。它识别 postgres 命令,但不是全部。现在当我编译时,我得到这个错误:

Connection.obj : error LNK2001: unresolved external symbol _PQconnectdb
1>C:\Users\Irfan\Desktop\IGD\DataCorroborationDLL\Release\Tests.exe : fatal error
LNK1120: 1 unresolved externals

4

0 回答 0