在Microsoft Visual c++ 2015中编译DLL -警告C4251需要有DLL接口供类的客户端使用-当使

Compiling DLL in Microsoft Visual C++ 2015 -- warning C4251 needs to have dll-interface to be used by clients of class -- when using Boost?

本文关键字:DLL 口供 接口 当使 客户端 C4251 c++ Visual Microsoft 2015 警告      更新时间:2023-10-16

所以,我正试图为我的一个大型项目编译一个DLL。我们的想法是把它分成几个部分。编译成DLL的库,以及链接到DLL的应用程序。我一直收到以下警告:

warning C4251: 'plf::lfInvalidIndexExcpt::message': class 'boost::container::basic_string<char,std::char_traits<char>,boost::container::new_allocator<char>>' needs to have dll-interface to be used by clients of class 'plf::lfInvalidIndexExcpt'

这是一直困扰我的代码。

我有我的DLL导出/导入宏定义如下:

#ifdef LF_ENGINE_EXPORTS  
#define LFE_API __declspec(dllexport)   
#else  
#define LFE_API __declspec(dllimport)   
#endif  
现在,我在中使用boost,在某一点上我有以下内容:
typedef boost::container::string lfString;

类lfinvalidindexexpt是这样定义的:

namespace plf
{
    class LFE_API lfInvalidIndexExcpt
    {
    public:
        explicit lfInvalidIndexExcpt(lfSize idx);
        lfInvalidIndexExcpt(lfSize idx, const lfString& descr);
        const char* what() const throw();
    private:
        lfString message;
        void makeMessage(lfSize idx, const lfString& descr);
    };
};

我应该提到lfSize只是std::size_t的一个类型定义。

我想知道的是这个警告实际上意味着什么,如果我可以在我的DLL中使用这样的Boost,如果有的话。此外,如果这不是正确的方式来使用Boost是什么?

谢谢,

扎克霜

所以,我似乎已经找到了解决我自己的问题,通过玩弄我的代码和窥探周围的StackOverflow!我似乎只需要做的是从类声明中删除DLL导出宏并将其添加到成员函数中。现在它似乎可以编译和工作了!

解决方案来自此StackOverflow帖子(由 first 回答):std::vector需要有dll接口由类'X警告

的客户端使用