C++ 在windows上连接到postgresql

C++ 在windows上连接到postgresql,c++,postgresql,C++,Postgresql,当我在cpp中为postgresql编写一些客户端代码时,我总是会遇到以下简单代码的问题: #include <iostream> #include <libpq-fe.h> #include <stdio.h> using namespace std; char pghost[] = "localhost"; char pgport[] = "5432"; char pgbase[] = "baza"; char pguser[] = "postgres"

当我在
cpp
中为
postgresql
编写一些客户端代码时,我总是会遇到以下简单代码的问题:

#include <iostream>
#include <libpq-fe.h>
#include <stdio.h>
using namespace std;

char pghost[] = "localhost";
char pgport[] = "5432";
char pgbase[] = "baza";
char pguser[] = "postgres";
char pgpass[] = "server";
char conninf[] = "host=localhost port=5432 database=postgres user=postgress password=server";

int main(){    
  PGconn *conn = PQsetdbLogin(pghost,pgport,NULL,NULL,pgbase,pguser,pgpass);

  if (PQstatus(conn) == CONNECTION_OK)
  {
    //if connected
    cout<<"Ok.\n";
  }
  else
  {  
    cout<<"ERROR: %s\n";
    PQfinish(conn);
    }
    return 0;
  }
}        
而且库中的其他函数也有很多错误

我做错了什么?如何在Windows上正确连接到此库

来自:

尝试传递
-lpq
标志,查看您提到的其他错误是否消失。

从:


尝试传递
-lpq
标志,查看您提到的其他错误是否消失。

您的libpq fe.h文件包含: 外部PGconn*PQsetdbLogin

还要检查你的LIB。可能是缺少一个libq-linker


在构建项目时,请尝试包含include/postgresql-L/lib-lpq。

您的libpq fe.h文件包含: 外部PGconn*PQsetdbLogin

还要检查你的LIB。可能是缺少一个libq-linker

在构建项目时,尝试包含include/postgresql-L/lib-lpq

C:\Users\Tom\Desktop\connect\connect.cpp|16|undefined reference to `PQsetdbLogin'| 
testlibpq.o: In function `main':
testlibpq.o(.text+0x60): undefined reference to `PQsetdbLogin'
testlibpq.o(.text+0x71): undefined reference to `PQstatus'
testlibpq.o(.text+0xa4): undefined reference to `PQerrorMessage'

This means you forgot -lpq.