Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

c++

dll

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

like image 918
jmasterx Avatar asked Nov 10 '10 14:11

jmasterx


1 Answers

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.

like image 151
Steve Townsend Avatar answered Sep 22 '22 06:09

Steve Townsend