4

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
Community
  • 1
  • 1
SeanRamey
  • 665
  • 7
  • 19
  • Are you sure the library in bin was build for MinGW? (Seems you are using mingw) – SergeyA Feb 25 '16 at 13:58
  • `\Bin32` are you on 32 or 64? – iksemyonov Feb 25 '16 at 13:59
  • Im using a 64bit PC with windows 7 64bit, but I am building a 32bit executable. I am using MinGW, or more accurately, I'm using TDM-GCC-64 , and the "-m32" flag is to build for 32bit. If the library wasn't built for MinGW then I guess I'm shit out of luck because that's the only one they have. – SeanRamey Feb 25 '16 at 14:09
  • also, it seems that it should be compatible with MinGW because I tried linking with the 64bit library just to be sure to try everything, and g++ complained that the library wasn't compatible. It doesn't have that complaint with the 32bit version, so it should be fine. – SeanRamey Feb 25 '16 at 14:19
  • check the vulkan SDK it should have a vulkan-1.lib for you to link with. – ratchet freak Feb 25 '16 at 14:23
  • @ratchet freak man you people really don't read do you? "g++ -m32 -LC:\VulkanSDK\1.0.3.1\Bin32 -lvulkan-1 main.obj -o VulkanApp.exe" – SeanRamey Feb 25 '16 at 14:25
  • WOW, I would love to know voted down my question! If you think that a question should be voted down, then you should be ready to post an answer. So far, nobody has given me an answer. – SeanRamey Feb 25 '16 at 14:50
  • 1
    Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Ivan Aksamentov - Drop Feb 25 '16 at 15:27
  • 1
    People were able to link a lib from LunarG SDK with MinGW-w64 (for x86_64). See [this](http://stackoverflow.com/questions/35529246/how-do-i-use-vulkan-with-mingw-r-x86-64-32-error) Q&A – Ivan Aksamentov - Drop Feb 25 '16 at 15:36
  • I actually looked at that page and tried it's solution (which didn't really apply well to me) but it didn't help at all. – SeanRamey Feb 25 '16 at 15:43
  • 1
    @SeanRamey: "*If you think that a question should be voted down, then you should be ready to post an answer.*" That's not what a downvote means. Indeed, that's usually the *opposite* of what a downvote means. Read the tooltip for what downvotes mean. – Nicol Bolas Feb 25 '16 at 19:07
  • @Nicol Bolas Actually, it does mean that. Just in a way that may not be too obvious. You see, if the question is not useful or unclear, then it should have an answer explaining why it is not useful or unclear or otherwise it should be answered if it is just a unresearched question that has an easy answer. See, if it is any of those things, then it shouldn't be hard to post an answer to explain. – SeanRamey Feb 25 '16 at 19:11
  • 1
    @SeanRamey: I've tried to compile exactly the same code with the same configurations (64bit) as [the answer I gave](http://stackoverflow.com/questions/35529246/how-do-i-use-vulkan-with-mingw-r-x86-64-32-error), just changing the tools to `TDM-GCC-64` (gcc version 5.1.0 - tdm64-1) and I can confirm that it does **not** work! The linker gave me a message: *"error adding symbols: File in wrong format"* for `vulkan-1.lib`. Restored the tools to `x86_64-posix-seh-rev0 - MinGW`, and all worked well again. – Gomiero Feb 26 '16 at 07:28
  • @Gomiero Ok, so you had to use MinGW for it to work? – SeanRamey Feb 26 '16 at 08:07
  • @SeanRamey: Yes, I had. I tested with `TDM-GCC-64` (right now, when I saw your comments) and it didn't recognize `vulkan-1.lib`'s format. Don't know why, but since I also had problems with TDM's `gfortran` to compile `libOpenBlas`, and it took some time until I find that it was a bug, I gave up to use TDM's distribution. – Gomiero Feb 26 '16 at 08:25
  • @Gomiero Ok, wow, well I'm using MinGW now but it still doesn't work. It gives me the same error as before. Are you using MinGW or MinGW-w64? Should it make a difference? And, if possible, could you post a link with the project file that works? – SeanRamey Feb 26 '16 at 08:30
  • 1
    @Gomiero Nevermind all that, I downloaded MinGW-w64 x86_64 posix seh rev0 just like you said, and it works perfectly! So, yeah, this must be a compiler/linker bug. – SeanRamey Feb 26 '16 at 08:39
  • 1
    @SeanRamey: Good to know that worked!! :) I hope someone could add more details about this bug to the answers. Maybe this can help more people in future. – Gomiero Feb 26 '16 at 08:47

2 Answers2

2

As I found out, (thanks to @Gomiero), if I try this same build with MinGW-w64 x86_64 posix seh rev0, it will work perfectly! Seems that TDM-GCC-64, as well as regular MinGW have issues with the "vulkan-1" library. So, this is summed up to being a compiler/linker bug!

SeanRamey
  • 665
  • 7
  • 19
0

Most of the time an Undefined reference come when you forgot to link a library. The compiler is able to see the definition thanks to the header file, but for create an executable file it need to have ether or the sources or a binary (.o,.obj,.a,.dll,.so,...) to link with it. When this file is not present it cannot see the definition. This is what undefined reference mean. Pay also attention to one thing I see you are on a 32 bit computer (-m32 == machine 32 bits) be sure to link with a 32 bit version of Vulkan library.

John_Sharp1318
  • 939
  • 8
  • 19
  • 1
    I know what an undefined reference means... What I want to know is why it can't find the function I'm giving it! As far as I know I'm linking it with the correct library, but the documentation leaves much to be desired. In fact, there basically is NO documentation of the libraries at all. Also, can you read at all??? "-LC:\VulkanSDK\1.0.3.1\Bin32 -lvulkan-1" – SeanRamey Feb 25 '16 at 14:11