How to use Vulkan with MinGW? (Error R_X86_64_32)

I am trying to set up a program with bare bones to use Vulkan. I installed the LunarG SDK. I have a tiny program that basically just calls vkCreateInstance. I compiled 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 should I do? Am I linking to the right library?

+4
source share
4 answers

I managed to compile a simple program with just a call vkCreateInstancefrom MinGW-64.

Perhaps the error you are getting is related to the flag -m64.

Follow 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, MinGW-W64)

g++:

:

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

:

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

gcc:

:

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

:

gcc -m64 -o dist/Debug/MinGW-Windows/vulkanfirsttest build/Debug/MinGW-Windows/main.o -L/C/VulkanSDK/1.0.3.1/Bin -lvulkan-1

:

#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);
}

:

Device created: 0000000000534FD0

+3

64- TDM-GCC, vulkan-1.dll . -m64, -, , vulkan-1.dll , ld.exe .

CMake:

...
FIND_PACKAGE(Vulkan REQUIRED)
IF(WIN32 AND NOT MSVC)
    GET_FILENAME_COMPONENT(Vulkan_LIBRARY_DIR ${Vulkan_LIBRARY} DIRECTORY)
    IF(NOT "${Vulkan_LIBRARY_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
        MESSAGE(WARNING "If linking to Vulkan fails, try copying vulkan-1.dll to the ${CMAKE_BINARY_DIR} and then set Vulkan_LIBRARY to ${CMAKE_BINARY_DIR}/vulkan-1.dll")
    ENDIF(NOT "${Vulkan_LIBRARY_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
ENDIF(WIN32 AND NOT MSVC)
TARGET_LINK_LIBRARIES(myprogram ${Vulkan_LIBRARY} ... )
...
+1

, , , , , . /: https://sourceforge.net/p/mingw-w64/support-requests/19/

dlltool vulkan-1.dll( howto - http://www.mingw.org/wiki/createimportlibraries). , , ( , gcc 1 undefined). , vulkan-1.def( , ):

LIBRARY vulkan-1.dll
vkAllocateCommandBuffers
vkAllocateDescriptorSets
vkAllocateMemory
; add functions as needed, one per line

dlltool -d vulkan-1.def -l libvulkan-1.a

-L. -lvulkan-1 . gcc:

gcc -g cube.c -o cube.exe -I /c/VulkanSDK/1.0.8.0/Include/ -D_WIN32 -DVK_USE_PLATFORM_WIN32_KHR -L . -lvulkan-1 -mwindows

, .

. wcstombs_s wcstombs . :

numConverted = wcstombs(argv[iii], commandLineArgs[iii], wideCharLen + 1);
0

Instead of using -lvulkan-1or fixing the problem with ddltool, you can try to specify explicitly vulkan-1.dlland it should allow characters.

gcc -std=c99 -m64 -g -Wall -Ic:\VulkanSDK\1.0.39.1\Include\vulkan vktest.c -o vktest c:\Windows\System32\vulkan-1.dll

0
source

Source: https://habr.com/ru/post/1629721/


All Articles