【问题标题】:PostgreSQL C++ Api getting error LNK1107: invalid or corrupt file: cannot read at 0x2E8PostgreSQL C++ Api 出现错误 LNK1107:文件无效或损坏:无法在 0x2E8 读取
【发布时间】:2014-06-14 17:20:59
【问题描述】:

我尝试使用 libpqxxpg_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 读取

我可以解决这个问题吗?

【问题讨论】:

    标签: c# c++ postgresql winapi libpq


    【解决方案1】:

    当您尝试链接 DLL(在本例中为 libpq.dll)而不是库 (libpq.lib) 时,通常会发生此错误。

    假设您从enterprisedb pre-compiled binaries 下载了适用于 Windows 的 PostgreSQL,则安装目录中有一个lib 目录,其中包含libpq.lib。这就是您要指示为 Visual Studio 项目的外部库的文件。

    【讨论】:

    • 好的!,谢谢我解决了这个错误。下一个错误 - “错误 LNK1120:1 未解决的外部”?谢谢回答。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-28
    • 2017-12-19
    • 2020-03-06
    • 2019-06-13
    • 1970-01-01
    • 2019-04-18
    • 2023-03-13
    相关资源
    最近更新 更多