简体   繁体   English

使用 AMD 的 Vulkan 内存分配器时出现链接器错误 (LNK2005)

[英]Linker error (LNK2005) when using AMD's Vulkan Memory Allocator

I have just started using AMD's VMA by including vk_mem_alloc.h in my header file with #define VMA_IMPLEMENTATION before it.我刚刚开始使用 AMD 的 VMA, vk_mem_alloc.h在我的头文件中包含#define VMA_IMPLEMENTATION在它之前添加#define VMA_IMPLEMENTATION But when I build the project, a lot of LNK2005 error appear.但是当我构建项目时,出现了很多LNK2005错误。

My file structure is like我的文件结构就像

VulkanBase ( .h + .cpp ) -(Base class of)-> ExApp (.cpp) VulkanBase ( .h + .cpp ) -(Base class of)-> ExApp (.cpp)

I have declared this library in VulkanBase.h file.我已经在VulkanBase.h文件中声明了这个库。 The errors are like all the members in vk_mem_alloc.h have already defined in ExApp.cpp .该错误是像所有的成员vk_mem_alloc.h中已经定义ExApp.cpp At the end of the error list, it showed that one or more multiply defined symbols found .在错误列表的末尾,它显示找到了one or more multiply defined symbols found

Does anyone have an idea?有没有人有想法? Thank you in advance.先感谢您。

the best thing to do is in you VulkanBase.h file include the vma header file and in your VulkanBase.cpp file before you include your VulkanBase.h file define the #define VMA_IMPLEMENTATION.最好的做法是在 VulkanBase.h 文件中包含 vma 头文件,并在包含 VulkanBase.h 文件之前在 VulkanBase.cpp 文件中定义 #define VMA_IMPLEMENTATION。 This way you only have one implementation of vma exist and it is compiled in your VulkanBase.cpp.这样你就只有一个 vma 实现存在,它被编译在你的 VulkanBase.cpp 中。 You can Include VulkanBase.h file in other .cpp/.h files which only has VMA declarations.您可以在其他只有 VMA 声明的 .cpp/.h 文件中包含 VulkanBase.h 文件。 Hope that helps希望有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM