I am trying to setup a bare bones program to use Vulkan. I installed the LunarG SDK. I have a tiny program that basically just calls vkCreateInstance
. I compiled with this line:
g++ -std=c++11 -I/c/VulkanSDK/1.0.3.1/Include -L/c/VulkanSDK/1.0.3.1/Bin main.cpp -lvulkan-1
I get this compiler error using 64-bit mingw (MSYS2):
relocation truncated to fit||R_X86_64_32 against symbol `__imp_vkCreateInstance' defined in .idata$5 section in C:\VulkanSDK\1.0.3.1\Bin/vulkan-1.lib(vulkan-1.dll.b)|
What do I do? Am I linking against the right library?
I was able to compile a simple program, with just a call to vkCreateInstance
with MinGW-64
.
Maybe the error you're getting is related to the -m64
flag.
Follow bellow my configuration:
With g++:
Compile:
g++ -m64 -std=c++11 -c -g -I/C/VulkanSDK/1.0.3.1/Include -MMD -MP -MF "build/Debug/MinGW-Windows/main.o.d" -o build/Debug/MinGW-Windows/main.o main.c
Link:
g++ -m64 -std=c++11 -o dist/Debug/MinGW-Windows/vulkanfirsttest build/Debug/MinGW-Windows/main.o -L/C/VulkanSDK/1.0.3.1/Bin -lvulkan-1
With gcc:
Compile:
gcc -m64 -c -g -I/C/VulkanSDK/1.0.3.1/Include -std=c11 -MMD -MP -MF "build/Debug/MinGW-Windows/main.o.d" -o build/Debug/MinGW-Windows/main.o main.c
Link:
gcc -m64 -o dist/Debug/MinGW-Windows/vulkanfirsttest build/Debug/MinGW-Windows/main.o -L/C/VulkanSDK/1.0.3.1/Bin -lvulkan-1
Source code:
#include <stdio.h>
#include <stdlib.h>
#include <vulkan/vulkan.h>
int main(int argc, char *argv[]) {
VkInstanceCreateInfo vk_info;
VkInstance inst = 0;
VkResult res;
vk_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
vk_info.pNext = NULL;
vk_info.pApplicationInfo = NULL;
vk_info.enabledLayerCount = 0;
vk_info.ppEnabledLayerNames = NULL;
vk_info.enabledExtensionCount = 0;
vk_info.ppEnabledExtensionNames = NULL;
res = vkCreateInstance(&vk_info, NULL, &inst);
if (res != VK_SUCCESS) {
// Error!
printf("Error %d\n", res);
return 1;
};
printf("Device created: %p\n", inst);
vkDestroyInstance(inst, NULL);
return (EXIT_SUCCESS);
}
Output:
Device created: 0000000000534FD0