PostgreSQL c++ Api获取错误LNK1107:无效或损坏的文件:无法在0x2E8读取
PostgreSQL C++ Api getting error LNK1107: invalid or corrupt file: cannot read at 0x2E8
我尝试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项目外部库的文件。
相关文章:
- 正在将csv文件读取为双精度矢量
- 将从格式化文本文件读取的文本数据存储到链表
- C++ 读取文件读取文件不正确
- 使用对象文件读取三角形数据网格
- 如何减慢从 BVH 文件读取的 opengl 动画?
- 从文件读取,并写入函数C++中的数组
- 从对象C++中的文件读取内容时出现分段错误
- 从文件读取并通过矢量输出到控制台
- 尝试将字符串从文件读取到无符号字符向量中
- 如何将文本文件读取到二维数组中并以 c++ 打印
- 简化文件读取的函数
- 如何将逗号分隔的文件读取为 2D int 数组?
- 在 c++ 中将数据从文件读取到队列中
- 'std::wstring_convert'尽可能多地转换(从 UTF8 文件读取块)
- C++,从文件读取到结构,然后读取到向量(结构被推入向量太多次,而不仅仅是一次)
- 文件读取C++包括空格键
- 从文件读取时未将值推回矢量
- 从文件 C++ 读取时的无限循环
- 从同一文件读取和写入?
- 从.txt文件读取到C++中的双精度向量