How do I use Vulkan with MinGW? (R_X86_64_32 error)

TheBuzzSaw picture TheBuzzSaw · Feb 20, 2016 · Viewed 7.7k times · Source

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?

Answer

Gomiero picture Gomiero · Feb 21, 2016

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:

  • Windows 8.1
  • NetBeans IDE 8.1
  • Vulkan SDK 1.0.3.1
  • gcc version 5.3.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project)

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