【问题标题】:C++: Warning inconsistent dll linkageC++:警告不一致的 dll 链接
【发布时间】:2016-05-14 06:25:28
【问题描述】:

我对 Visual Studio(在 C++ 中)有疑问

我收到警告,但我不知道为什么,因为我从来没有两次调用同一个变量。

function: inconsistent dll linkage

警告列表:(法语)

我在 microsoft 上阅读:Compiler Warning (level 1) C4273,但我真的不知道这是否是我的问题,因为示例与我的不同。

我还阅读了About inconsistent dll linkage (StackOverflow,它告诉我因为我在 dll 中使用了 MFC,但我没有检查标头 MFC。

这是我的“PayRespectdll.h”

#pragma once

#ifdef PAYRESPECTDLL_EXPORTS
#define PAYRESPECTDLL_API __declspec(dllexport) 
#else
#define PAYRESPECTDLL_API __declspec(dllimport) 
#endif

#include <ctime>
#include <time.h>
#include <string>

namespace PayRespectDLL
{
    class PayRespect
    {
    private:
        static struct std::tm when;
    public:
        static PAYRESPECTDLL_API bool is_setup();
        static PAYRESPECTDLL_API void setup(std::string date);
        static PAYRESPECTDLL_API bool is_possible();
    }
}

PayRespectDLL.cpp:

// PayRespectDLL.cpp :
//

#include "stdafx.h"
#include "PayRespectDLL.h"
#include <stdexcept>
#include <time.h>
#include <string>
#include <stdlib.h>


using namespace std;

namespace PayRespectdll
{
    bool PayRespect::is_setup()
    {
        return false;//already_setup;
    }

    // setup attempt String: hh:mm:ss.
    void PayRespect::setup(string date)
    {
        return;
    }

    bool PayRespect::is_possible()
    {
        return true;
    }
}

谢谢!

【问题讨论】:

  • 当编译器解析声明并看到 __declspec(dllimport) 时,您将收到此警告。但是后来也看到了函数的定义。这当然是不正确的,它不能同时从另一个 DLL 导入和 由您的代码实现。发生这种情况的最明显原因是您忘记定义或拼写错误 PAYRESPECTDLL_EXPORTS
  • 当我从其他应用程序调用我的 dll 时.. 我只需要添加“.h”... 不定义什么?我遵循创建 dll 的教程,我认为它从未看到我需要在我的解决方案中定义一些东西。你能给我一个正确定义它的教程吗?
  • 右键单击您的 DLL 项目 > 属性 > C/C++ > 预处理器 > 预处理器定义设置。添加 PAYRESPECTDLL_EXPORTS。对所有其他配置重复此操作。这应该是可以发现的,再花一个小时环顾四周。有不明白的地方按 F1。

标签: c++ dll visual-studio-2015


【解决方案1】:

鉴于您使用的是 MFC,我曾经遇到过编译错误(“不一致的 DLL 链接”),因为当方法不是“内联”时,我在头文件中定义了方法体。

【讨论】:

    猜你喜欢
    • 2011-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多