/ MT触发了C4275警告,但没有触发/ MD [英] /MT triggered C4275 warning, but not in /MD

查看:90
本文介绍了/ MT触发了C4275警告,但没有触发/ MD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一节课   



     

    #ifdef DLLEXPORT 

    #define EXPORT __declspec(dllexport)

    #else

    #define EXPORT __declspec(dllimport)

    #endif

    

  &NBSP; #include< iostream>

  &NBSP; #include< memory>

  &NBSP; class EXPORT A:public std :: iostream

  &NBSP; {

  &NBSP;公众:

  &NBSP; 使用Base = std :: iostream;

  &NBSP; A(std :: streambuf * buf):Base(buf){}

  &NBSP; ~A(){}

  &NBSP; void Test();

  &NBSP;在Dll1.h中定义并在Dll1.cpp中实施的
$
, 
$


  &NBSP; #include" Dll1.h"

    

  &NBSP; void A :: Test()

  &NBSP; {

  &NBSP; std :: cout<< "你好" << std :: endl;

  &NBSP; }


然后导出到Dll1.dll。



然后在我的项目代码source.cpp中,我包括Dll1.h.
$


  &NBSP; #include" Dll1.h"

    

  &NBSP; int main()

  &NBSP; {

  &NBSP; A a(nullptr);

  &NBSP; a.Test();

  &NBSP; 返回0;

  &NBSP; } b
$ b如果运行时库的msvc编译器标志设置为/ MT,那么我收到了C4275警告。但是,如果我将其更改为/ MD,那么我可以编译并链接Dll1.dll



我理解/ MT告诉编译器对运行时的静态链接,而/ MD是使用动态链接。但为什么会导致C4275警告?

解决方案

您确定更改了所有配置的设置吗?如果在配置设置为Debug(活动)时设置某些内容,然后在配置设置为all时更改某些内容,则可能导致不匹配,您可能无法实现
原因。检查设置并确保它们符合所有配置的预期。


此外,如果您使用_DEBUG宏或类似的东西,请检查以确保不是原因。


I have a class   

     
    #ifdef DLLEXPORT 
    #define EXPORT __declspec(dllexport)
    #else
    #define EXPORT __declspec(dllimport)
    #endif
    
    #include <iostream>
    #include <memory>
    class EXPORT A : public std::iostream
    {
    public:
    using Base = std::iostream;
    A(std::streambuf* buf) : Base(buf) {}
    ~A() {}
    void Test();
    };

defined in Dll1.h and implemented in Dll1.cpp, 

    #include "Dll1.h"
    
    void A::Test()
    {
    std::cout << "Hello" << std::endl;
    }

then exported to Dll1.dll.

Then in my project code, source.cpp, I include Dll1.h.

    #include "Dll1.h"
    
    int main()
    {
    A a(nullptr);
    a.Test();
    return 0;
    }

If the msvc compiler flags for run-time libraries is set to /MT, then I got C4275 warning. But if I change it to /MD, then I can compile and link Dll1.dll

I understand /MT tells compiler to static link against runtime, whereas /MD is to use dynamic link. But why this will cause C4275 warning?

解决方案

Are you sure you changed the settings for all configurations? If you set something when the configuration is set to Debug (active) and then later change something when the configuration is set to all then it can cause a mismatch and you might not realize why. Check the settings and ensure that they are as expected for all configurations.

Also if you use the _DEBUG macro or something like that then check to ensure that is not the cause.


这篇关于/ MT触发了C4275警告,但没有触发/ MD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆