c++cmakevulkan

Unresolved external symbol using VulkanMemoryAllocator


I installed VulkanMemoryAllocator by adding a git submodule and using add_subdirectory(vma) in my CMakeList.txt.

And in the subproject which requires VMA, I do configured the link by adding target_link_libraries(myproject PRIVATE GPUOpen::VulkanMemoryAllocator)

However, I still receive such errors:

main.cpp.obj : error LNK2019: unresolved external symbol vmaCreateAllocator referenced in function "private: void __cdecl hi::v1::gfx_device::initialize_device(void)" (?initialize_device@gfx_device@v1@hi@@AEAAXXZ)
main.cpp.obj : error LNK2019: unresolved external symbol vmaDestroyAllocator referenced in function "public: __cdecl hi::v1::gfx_device::~gfx_device(void)" (??1gfx_device@v1@hi@@QEAA@XZ)

root/CMakeList.txt:

project(myproj1 CXX)

find_package(Vulkan REQUIRED)

add_subdirectory(hikogui)
add_subdirectory(vma)
add_subdirectory(myproject)

./root/myproject/CMakeList.txt:

add_library(myproject SHARED ${SOURCES} ${HEADERS})

target_link_libraries(myproject PRIVATE ${Vulkan_LIBRARY} Vulkan::Vulkan)
target_link_libraries(myproject PRIVATE GPUOpen::VulkanMemoryAllocator)
target_link_libraries(myproject PRIVATE hikogui)

Solution

  • Did you read the VMA project setup documentation?

    In exactly one CPP file define following macro before this include. It enables also internal definitions.

    #define VMA_IMPLEMENTATION
    #include "vk_mem_alloc.h"