0

So, I'm trying to compile a DLL for a large project of of mine. The idea is for it to have several parts. A library, of sorts, which gets compiled into a DLL, and an application that the DLL gets linked into. I keep getting the following warning:

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'

Here is the code that has been giving me trouble.

I have my DLL export/import macro defined as follows:

#ifdef LF_ENGINE_EXPORTS  
#define LFE_API __declspec(dllexport)   
#else  
#define LFE_API __declspec(dllimport)   
#endif  

Now, I'm using boost with my library and at one point I have the following:

typedef boost::container::string lfString;

The class lfInvalidIndexExcpt is defined like this:

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);

    };
};

I should probably mention that lfSize is just a typedef for std::size_t.

All I'm wondering is what this warning actually means and if I can use Boost like this in my DLL, if at all. Also, if this is not the proper way to use Boost what is?

Thanks,

-Zack Frost

Zack Frost
  • 155
  • 1
  • 12
  • 1
    It is a warning to remind you that, if the client of your DLL would ever use the *message* member, then it is going to fail to link. Which could happen if you have inline functions in your class. Or if the client creates or destroys an instance of this class, that requires the constructor and destructor to be exported as well. The destructor is the likely failure mode, seems you expose this as an exception type that is thrown across the DLL boundary. Always troublesome and not in the least because of the Boost version dependency. Consider deriving from std::exception instead. – Hans Passant Nov 09 '16 at 16:58
  • @Hans Passant Thanks for the info! That helped. Armed with that knowledge I was able to figure out how to work around it. I will post an answer with my solution momentarily. – Zack Frost Nov 09 '16 at 17:06

1 Answers1

1

So, I seem to have found the solution to my own problem both by toying with my code and snooping around StackOverflow! I seems that I simply needed to do was remove the DLL export macro from the class declaration and add it to the member functions. It now seems to compile and work just fine!

The solution is from this StackOverflow post (answer by frast): std::vector needs to have dll-interface to be used by clients of class 'X warning

Community
  • 1
  • 1
Zack Frost
  • 155
  • 1
  • 12