PostgreSQL c++ Api获取错误LNK1107:无效或损坏的文件:无法在0x2E8读取
本文关键字:文件 读取 0x2E8 损坏 Api c++ 获取 取错误 无效 LNK1107 PostgreSQL | 更新日期: 2023-09-27 18:08:33
我尝试libpqxx和pg_bulkload为c++数据批量加载器从我的简单c#应用程序。因为这两个库在我的PC上最终不支持。我现在,用本地PostgreSQL libpq方法创建一个简单的DLL项目。
CPPApp.h
#pragma once
#ifdef CPPAPP_EXPORTS
#define CPPAPP_API __declspec(dllexport)
#else
#define CPPAPP_API __declspec(dllimport)
#endif
#include "libpq-fe.h"
extern CPPAPP_API PGconn* conn;
#ifdef __cplusplus
CPPAPP_API extern "C" {
#endif
void OpenDb(const char* connStr);
void CloseDb(void);
int getVersion(void);
#ifdef __cplusplus
}
#endif
CPPApp.cpp
#include "stdafx.h"
#include "CPPApp.h"
#include <iostream>
using namespace std;
CPPAPP_API PGconn* conn = nullptr;
void OpenDb(const char* connStr)
{
conn = PQconnectdb(connStr);
if (PQstatus(conn) != CONNECTION_OK)
{
cout << "Connection to database failed." << endl;
CloseDb();
}
cout << "Connection to database - OK" << endl;
}
void CloseDb(void)
{
PQfinish(conn);
}
int getVersion(void)
{
int version = PQserverVersion(conn);
cout << "PostgreSQL version is " << version << endl;
return version;
}
错误:错误LNK1107:无效或损坏的文件:无法读取0x2E8
我可以解决这个问题吗?
当您尝试链接DLL(在本例中为libpq.dll
)而不是库(libpq.lib
)时,通常会发生此错误。
假设您从enterprisedb预编译的二进制文件中下载了PostgreSQL for Windows,在安装目录中有一个lib
目录和libpq.lib
。这就是你想要指定为Visual Studio项目外部库的文件。