Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
271 views
in Technique[技术] by (71.8m points)

c++ - std::vector needs to have dll-interface to be used by clients of class 'X<T> warning

I'm trying to make my library exportable as a DLL but I'm getting a lot of these warnings for one specific class that uses std::vector:

template <typename T>
class AGUI_CORE_DECLSPEC AguiEvent {
    typedef void (*AguiCallbackFptr)(T arg, AguiWidget* sender);
std::vector<AguiCallbackFptr> events;
public:
    void call(AguiWidget* sender, T arg) const;
    void addHandler(AguiCallbackFptr proc);
    void removeHandler(AguiCallbackFptr proc);
    void removeHandler();
    AguiEvent();
};

I get warnings like these:

Warning 57 warning C4251: 'AguiEvent::events' : class 'std::vector<_Ty>' needs to have dll-interface to be used by clients of class 'AguiEvent'

I tried to find how to do this properly but MSDN's documentation is very Windows Only, and I need this to be cross platform so that it only does MS specific stuff when AGUI_CORE_DECLSPEC is in fact defined.

What should I do to get rid of these warnings?

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Exporting from a DLL is platform-specific. You will have to fix this for Windows (basically use declspec(dllexport/dllimport) on the instantiated class template) and encapsulate the required code in your Windows-specific preprocessor macro.

My experience is that exporting STL classes from DLLs on Windows is fraught with pain, generally I try to design the interface such that this is not needed.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...