VulkanMemoryAllocator icon indicating copy to clipboard operation
VulkanMemoryAllocator copied to clipboard

Vma c interface issue

Open bensam00 opened this issue 3 years ago • 5 comments

I have included vk_mem_alloc.h on my c project and in my cmake file i added it as an interface like this

add_library(include INTERFACE) target_include_directories(include INTERFACE include)

while include is the folder where i put my vma header file and i added it without #define VMA_IMPLEMENTATION as mention in documentation like this #include "include/vk_mem_alloc.h"

and yet it always gives me undefined reference to 'vmaCreateAllocator' when i try to initialize it

im using fedora 37 with vulkan 1.3

bensam00 avatar Dec 24 '22 16:12 bensam00

"Undefined reference" likely means that you didn't include VMA implementation in your project. Cmake script is provided as an external contribution. Recommended way to use the library is to add "vk_mem_alloc.h" file directly to your project. Please follow instructions from documentation https://gpuopen-librariesandsdks.github.io/VulkanMemoryAllocator/html/quick_start.html. Long story short, in exactly one C++ source file of your code you need to #include the VMA header preceded by #define VMA_IMPLEMENTATION so the internal implementation of the library is compiled. Only then your project will include implementation of functions declared by the header.

adam-sawicki-a avatar Dec 28 '22 09:12 adam-sawicki-a

mold: error: /usr/lib64/libVulkanMemoryAllocator.a(VmaUsage.cpp.o):(.text): R_X86_64_PC32 relocation at offset 0x1987 against symbol 'vtable for VmaBlockMetadata' can not be used; recompile with -fPIC i get this error, i'm already compiling and linking with -fPIC but its probably the library that didnt compile and link with -fPIC can you add this to the CMake?

ghost avatar Jan 04 '23 13:01 ghost

This library is developed mostly on and for Windows + Visual Studio. I don't know what is -fPIC so I am not sure whether I should add this option to CMake.

Please try to include "vk_mem_alloc.h" directly in your project code, like the documentation recommends, instead of using it as a separate library with CMake and see if it helps on your platform.

adam-sawicki-a avatar Jan 04 '23 13:01 adam-sawicki-a

i did (i am using the c interface, i compiled the library, linked it, and included the vk_mem_alloc.h in my files) -fPIC mean position independent code which libraries usually get compiled with (I tested and -fPIC fixes the problems)

ghost avatar Jan 04 '23 15:01 ghost

I believe this issue can now be closed with all the CMake fixes made to master.

-fPIC doesn't apply at all anymore now that GPUOpen::VulkanMemoryAllocator is a minimal header only library like Vulkan::Headers.

The CMake now nicely compliments the existing documentation (https://gpuopen-librariesandsdks.github.io/VulkanMemoryAllocator/html/quick_start.html) instead of contrasting it by building and enforcing binaries on the user.

juan-lunarg avatar Jul 11 '23 17:07 juan-lunarg