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
withMinGW-64
.Maybe the error you're getting is related to the
-m64
flag.Follow bellow my configuration:
With g++:
Compile:
Link:
With gcc:
Compile:
Link:
Source code:
Output:
Device created: 0000000000534FD0
You guys were both more lucky than me, but then again, I was trying to build the cube example. I kept getting the relocation truncated problem and after some digging, managed to connect it to an old bug report/support request: https://sourceforge.net/p/mingw-w64/support-requests/19/
My solution was to use dlltool and extract the symbols from vulkan-1.dll (another old howto - http://www.mingw.org/wiki/createimportlibraries). This didn't work fully as it couldn't extract any symbols so I had to manually fill them in (luckily, gcc outputs 1 line per undefined symbol). Basically, here's the beginning of my vulkan-1.def file (append your functions, one per line to the end of it):
After preparing this file, run
Now you can use -L. -lvulkan-1 and avoid the relocation issues. My full gcc command line is:
And voila, cube works.
Note: I also needed to replace wcstombs_s to wcstombs for it to compile. The resulting line is now:
Instead of using
-lvulkan-1
or going through the trouble with ddltool, you can try explictly listing thevulkan-1.dll
and it should resolve the symbols.gcc -std=c99 -m64 -g -Wall -Ic:\VulkanSDK\1.0.39.1\Include\vulkan vktest.c -o vktest c:\Windows\System32\vulkan-1.dll
I was able to get it working with TDM-GCC 64-bit by copying vulkan-1.dll to the current directory, and linking it to that. The -m64 doesn't seem to be necessary, but if vulkan-1.dll is not in current working directory, ld.exe crashes.
CMake configuration: