将__declspec(dllexport)添加到结构中会导致编译错误

时间:2019-05-26 20:51:42

标签: visual-studio-2019

我在DLL中有一个结构,到目前为止,该结构仅在该DLL中使用过。 我想通过指针在另一个DLL中使用该结构。因此,我在结构定义中添加了__declspec(dllexport)。简单地添加该dll导出语句现在会导致该结构无法编译(不仅仅是常规的DLL导出警告)。这是我第一次看到这种行为。我正在使用Visual Studio2019。我不知道潜在的问题是什么。

仅将'__declspec(dllexport)'添加到struct / class会使编译失败的原因是什么?

struct __declspec(dllexport) PipelineManager {
// ...
private:
    std::unordered_map<std::string, std::string>            mPathToName;
    std::unordered_map<std::string, vko::PipelineLayout>    mLayouts;
    std::unordered_map<std::string, vko::GraphicsPipeline>  mPipelines;
    std::unordered_map<std::string, std::unique_ptr<GraphicsPipelineDef>> mDefs;
};

以下大部分错误:

1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.21.27619\include\xmemory0(820,1): error C2280:  'std::pair<const _Kty,_Ty>::pair(const std::pair<const _Kty,_Ty> &)': attempting to reference a deleted function
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.21.27619\include\xmemory0(820,1): error C2280:         with
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.21.27619\include\xmemory0(820,1): error C2280:         [
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.21.27619\include\xmemory0(820,1): error C2280:             _Kty=std::string,
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.21.27619\include\xmemory0(820,1): error C2280:             _Ty=std::unique_ptr<ngen::rendo::GraphicsPipelineDef,std::default_delete<ngen::rendo::GraphicsPipelineDef>>
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.21.27619\include\xmemory0(820,1): error C2280:         ] (compiling source file Z:\NGEN\Source\Renderer\GpuProgramManager.cpp)
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.21.27619\include\utility(133): message :  see declaration of 'std::pair<const _Kty,_Ty>::pair'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.21.27619\include\utility(133): message :         with
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.21.27619\include\utility(133): message :         [
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.21.27619\include\utility(133): message :             _Kty=std::string,
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.21.27619\include\utility(133): message :             _Ty=std::unique_ptr<ngen::rendo::GraphicsPipelineDef,std::default_delete<ngen::rendo::GraphicsPipelineDef>>
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.21.27619\include\utility(133): message :         ] (compiling source file Z:\NGEN\Source\Renderer\GpuProgramManager.cpp)
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.21.27619\include\utility(133,5): message :  'std::pair<const _Kty,_Ty>::pair(const std::pair<const _Kty,_Ty> &)': function was implicitly deleted because a data member invokes a deleted or inaccessible function 'std::unique_ptr<ngen::rendo::GraphicsPipelineDef,std::default_delete<_Ty>>::unique_ptr(const std::unique_ptr<_Ty,std::default_delete<_Ty>> &)'
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.21.27619\include\utility(133,5): message :         with
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.21.27619\include\utility(133,5): message :         [
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.21.27619\include\utility(133,5): message :             _Kty=std::string,
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.21.27619\include\utility(133,5): message :             _Ty=std::unique_ptr<ngen::rendo::GraphicsPipelineDef,std::default_delete<ngen::rendo::GraphicsPipelineDef>>
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.21.27619\include\utility(133,5): message :         ]
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.21.27619\include\utility(133,5): message :         and
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.21.27619\include\utility(133,5): message :         [
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.21.27619\include\utility(133,5): message :             _Ty=ngen::rendo::GraphicsPipelineDef
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\VC\Tools\MSVC\14.21.27619\include\utility(133,5): message :         ] (compiling source file Z:\NGEN\Source\Renderer\GpuProgramManager.cpp)

// ...

1>Z:\NGEN\Source\Renderer/PipelineManager.hpp(67): message :  see reference to function template instantiation 'std::unordered_map<std::string,std::unique_ptr<ngen::rendo::GraphicsPipelineDef,std::default_delete<_Ty>>,std::hash<_Kty>,std::equal_to<_Kty>,std::allocator<std::pair<const _Kty,std::unique_ptr<_Ty,std::default_delete<_Ty>>>>>::unordered_map(const std::unordered_map<_Kty,std::unique_ptr<_Ty,std::default_delete<_Ty>>,std::hash<_Kty>,std::equal_to<_Kty>,std::allocator<std::pair<const _Kty,std::unique_ptr<_Ty,std::default_delete<_Ty>>>>> &)' being compiled
1>Z:\NGEN\Source\Renderer/PipelineManager.hpp(67): message :         with
1>Z:\NGEN\Source\Renderer/PipelineManager.hpp(67): message :         [
1>Z:\NGEN\Source\Renderer/PipelineManager.hpp(67): message :             _Ty=ngen::rendo::GraphicsPipelineDef,
1>Z:\NGEN\Source\Renderer/PipelineManager.hpp(67): message :             _Kty=std::string
1>Z:\NGEN\Source\Renderer/PipelineManager.hpp(67): message :         ] (compiling source file Z:\NGEN\Source\Renderer\GpuVM.cpp)
1>Z:\NGEN\Source\Renderer/PipelineManager.hpp(66): message :  see reference to class template instantiation 'std::unordered_map<std::string,std::unique_ptr<ngen::rendo::GraphicsPipelineDef,std::default_delete<_Ty>>,std::hash<_Kty>,std::equal_to<_Kty>,std::allocator<std::pair<const _Kty,std::unique_ptr<_Ty,std::default_delete<_Ty>>>>>' being compiled
1>Z:\NGEN\Source\Renderer/PipelineManager.hpp(66): message :         with
1>Z:\NGEN\Source\Renderer/PipelineManager.hpp(66): message :         [
1>Z:\NGEN\Source\Renderer/PipelineManager.hpp(66): message :             _Ty=ngen::rendo::GraphicsPipelineDef,
1>Z:\NGEN\Source\Renderer/PipelineManager.hpp(66): message :             _Kty=std::string
1>Z:\NGEN\Source\Renderer/PipelineManager.hpp(66): message :         ] (compiling source file Z:\NGEN\Source\Renderer\GpuVM.cpp)

0 个答案:

没有答案