FINAL EDIT: This is compiler/linker bug with TDM_GCC. See answer.
EDIT: This is not a duplicate as far as I can tell. The problem appears to be a simple noob error, but this is not the case. I have linked to the correct Vulkan library "vulkan-1.lib" using TDM-GCC-64 which is the GCC/MinGW toolkit for windows, and used example code from the VulkanSDK examples. This page How do I use Vulkan with MinGW? (R_X86_64_32 error) also confirms that it can be run on MinGW which should be no different from TDM-GCC-64 as it uses parts of MinGW. If this is a duplicate with a simple answer, then I am sorry for asking, but so far nobody has solved this "simple" problem.
EDIT2: Here is my project files. Just edit the makefile however you need to and run "BUILD.bat". http://www.filedropper.com/vulkanapp_1
I have downloaded the LunarG Vulkan SDK v1.0.3.1 and installed it. I have a very simple program that attempts to create an instance of Vulkan and exits.
The output I get when I try to build the program with g++ is:
C:\VulkanSDK\1.0.3.1\Bin32/vulkan-1.lib: error adding symbols: File in wrong format collect2.exe: error: ld returned 1 exit status
My makefile looks like this:
VulkanApp: main.obj g++ -m32 -LC:\VulkanSDK\1.0.3.1\Bin32 main.obj -o VulkanApp.exe -lvulkan-1 main.obj: main.cpp g++ -m32 -IC:\VulkanSDK\1.0.3.1\Include -c main.cpp -o main.obj clean: del *.exe *.obj
What am I doing wrong? I am linking agaist the right library, correct?
Here's my program code:
#include <vulkan/vulkan.h>
//#include <vulkan/vk_sdk_platform.h>
#include <iostream>
#include <cstdlib>
#define APP_SHORT_NAME "VulkanApp"
int main()
{
// initialize the VkApplicationInfo structure
VkApplicationInfo app_info = {};
app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
app_info.pNext = NULL;
app_info.pApplicationName = APP_SHORT_NAME;
app_info.applicationVersion = 1;
app_info.pEngineName = APP_SHORT_NAME;
app_info.engineVersion = 1;
app_info.apiVersion = VK_API_VERSION;
// initialize the VkInstanceCreateInfo structure
VkInstanceCreateInfo inst_info = {};
inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
inst_info.pNext = NULL;
inst_info.flags = 0;
inst_info.pApplicationInfo = &app_info;
inst_info.enabledExtensionCount = 0;
inst_info.ppEnabledExtensionNames = NULL;
inst_info.enabledLayerCount = 0;
inst_info.ppEnabledLayerNames = NULL;
VkInstance inst;
VkResult res;
res = vkCreateInstance(&inst_info, NULL, &inst); // <- undefined Reference here
if (res == VK_ERROR_INCOMPATIBLE_DRIVER) {
std::cout << "cannot find a compatible Vulkan ICD\n";
exit(-1);
} else if (res) {
std::cout << "unknown error\n";
exit(-1);
}
vkDestroyInstance(inst, NULL); // <- undefined reference here
return 0;
}
#endif