Hello I am currently migrating my codebase to using translate-c and modules that compile C/C++ using modules instead of @cImport. My project is a game engine using Vulkan as its backend. All my other dependencies have been straightforward to migrate, but I have run into trouble with AMD’s Vulkan Memory Allocator (VMA). It is a nearly purely C++ header file (It has a C API), but it NEEDS to be compiled by LLVM since it uses so many C++ features (Templates). I had this same issue with other libraries, but I was able to translate-c them accordingly.
I get the following error when trying to use the module:
src/graphics.zig:5:21: error: no module named 'vma' available within module 'root'
const vma = @import("vma");
Here is the complete source code for vma.cpp:
#define VMA_IMPLEMENTATION
#include <vk_mem_alloc.h>
#include <vulkan/vulkan.h>
It is defined as follows in my build.zig:
const vma_mod = b.createModule(.{
.optimize = optimize,
.target = target,
.link_libc = true,
.link_libcpp = true,
});
vma_mod.addCMacro("VMA_IMPLEMENTATION", "");
vma_mod.addCSourceFile(.{
.file = b.path("lib/vma.cpp"),
.flags = &.{"-lc++"},
});
vma_mod.addIncludePath(b.path("lib/VulkanMemoryAllocator-3.2.1/include"));
vma_mod.linkSystemLibrary("vulkan", .{ .needed = true });
Then in my main executable’s root module I’m importing it as follows:
const ceres_voxel = b.addExecutable(.{
.name = "Engine",
.use_llvm = true,
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
.imports = &.{
...
.{
.name = "vma",
.module = vma_mod,
},
...
},
}),
});
I have no compilation errors from the vma module and if I use ceres_voxel.root_module.addImport() instead of adding the module to the struct on definition I have the same issue.
I like to stay on the latest tagged release so any help is appreciated!
(This happens in both 0.17 and 0.17.1)
(Let me know if you want the full source of the build.zig and I will reply with it)