0

I am developing a shared library but the compiler came up with the warning C4351. My OS is a x64 Windows 10 1903 build 18362.267, my IDE is Visual Studio 2019, C++17.

I've tried adding a SIMPLECORE_API. But this ends with syntax error.

simplecore.h: // You can trust the class osdetection.h. It derives from Qt's library which only defines the macro OS_WIN.

#ifndef SIMPLECORE_H
#define SIMPLECORE_H

#include "osdetection.h"

#ifdef SIMPLECORE_EXPORTS

#ifdef _MSC_VER
#define SIMPLECORE_API __declspec(dllexport)
#else
#define SIMPLECORE_API
#endif // OS_LINUX

#elif defined(SIMPLELIBS_TEST)
#define SIMPLECORE_API 
#endif // SIMPLECORE_EXPORTS

#endif // !SIMPLECORE_H

The error class:

#ifndef AVECTOR_H
#define AVECTOR_H

#include <list>
#include <vector>
// ... some includes
// ..

template<class T>
class AVector : public std::vector<T> { // there's the warning
public:
    using std::vector<T>::vector; // makes std::vector's public functions from another class accessible, so I must not delete that
// ...
// unimportant functions 
// ...
};

// function definitions

#endif // !AVECTOR_H

The class generated the following warning:

Warning C4251 'std::vector<T,std::allocator<_Ty>>::_Mypair': class 'std::_Compressed_pair<std::allocator<_Ty>,std::_Vector_val<std::_Simple_types<_Ty>>,true>' needs to have dll-interface to be used by clients of class 'std::vector<T,std::allocator<_Ty>>'

How can I fix it? I do not want to ignore it by disabling it.

1201ProgramAlarm
  • 32,384
  • 7
  • 42
  • 56
  • 1
    It's a bad idea to expose STL classes in a DLL, as binary compatibility isn't guaranteed. A more portable solution would be to expose a C or a COM interface. – rustyx Aug 11 '19 at 20:12
  • 1
    What is it you are exporting? You can't export a template from a DLL. – Igor Tandetnik Aug 11 '19 at 21:04
  • How are you instantiating `AVector`? (What class are you passing in for `T`?) Are there any other informational lines associated with the warning? – 1201ProgramAlarm Aug 11 '19 at 23:10

0 Answers0