0

I'm developing a project on DevC++ which uses MinGW64. On Windows 7 (i don't know if this can be related to my issue).

I had a problem compiling a C++ program where I call the function GetFileVersionInfoSize(), which is:

main.cpp:(.text+0x51): undefined reference to `GetFileVersionInfoSizeA'

After two days of researching, I understood that I have to include in the parameters of the linker the "version.lib" file, which is missing in my computer, I searched it everywhere. I can't even find a download mirror on the web, so I'm asking, does anybody know where I can find version.lib? Maybe somewhere hidden in my PC or in the web? Maybe with a new installation of MinGW64? I don't know, since my installation of MinGW64 came with DevC++.

Thanks for reading.

buda_pest
  • 46
  • 1
  • 5
  • Maybe not helpful, but the name of the file is `Version.lib` (note uppercase V) - this *may* make a difference (but shouldn't for searching on Windows). May affect MinGW64, though? – Adrian Mole Jan 02 '20 at 00:32
  • @AdrianMole thanks for making me notice that, even if it's minor. Searching on Windows with uppercase V didn't help of course. At this point it's more like a research on the web for a download. – buda_pest Jan 02 '20 at 00:38
  • 1
    As MinGW64 uses the Unix nameing convention for libraries it will be called something starting with `libversion` and your linker command should include `-lversion` – Richard Critten Jan 02 '20 at 00:39
  • But I'm amazed that MingW64 doesn't have this core file! I just searched my HD and even `Borland C Version 5` (I use that for testing code compatibility) has it, as does `WatCom C`. You could try installing a Windows SDK - I think MinGW can work with these. – Adrian Mole Jan 02 '20 at 00:40

2 Answers2

0

Since it's a environment built for GCC, library names will follow Nix conventions:

  • Start with lib: libversion
  • Extension can be either .so or .a (depending on the library being dynamic or static)

Typically (depending on default MinGW installation), it should reside in ${MINGW_INSTALL_DIR}/x86_64-w64-mingw32/lib/libversion.a.
One installation example is: f:\Install\Qt\Qt\Tools\mingw730_64\x86_64-w64-mingw32\lib\libversion.a.

According to [Archive.Web - MinGW]: HOWTO Specify the Location of Libraries for use with MinGW (Determining MinGW's Default Library Search Path section), it can be retrieved by:

[cfati@cfati-5510-0:/cygdrive/e/Work/Dev/StackOverflow]> x86_64-w64-mingw32-ld.exe --verbose | grep SEARCH_DIR | tr -s ' ;' \\012
SEARCH_DIR("=/usr/x86_64-w64-mingw32/lib")
SEARCH_DIR("=/usr/local/lib")
SEARCH_DIR("=/lib")
SEARCH_DIR("=/usr/lib")

But since it's a system library, you shouldn't care about its path, MinGW should find it automatically, all you have to do is pass it to the linker (using the standard ways).

CristiFati
  • 38,250
  • 9
  • 50
  • 87
  • Yes, I found it, but the result was the same of when I tried to include the .dll file `version.dll`. When I run the program, a popup displays *"main.exe has stopped working"*. I also tried with -lversion such as @RichardCritten said, but same thing happened. – buda_pest Jan 02 '20 at 00:59
  • Then that's the next step. Since you managed to run your program, it means that it was successfully built, which I think was the purpose of the question. When running, make sure *${MINGW_INSTALL_DIR}/bin* is in *%PATH%*. – CristiFati Jan 02 '20 at 01:02
  • Open a *cmd* terminal, in the dir where your built executable is located, type `set PATH=%PATH%;${MINGW_INSTALL_DIR}/bin` (obviously *${MINGW\_INSTALL\_DIR}* is just a placeholder for your installation directory), then run your executable from that terminal. – CristiFati Jan 02 '20 at 01:09
  • Do I need double quotes for *${MINGW_INSTALL_DIR}*? I'm **very** unexperienced. And it's 2am tho. – buda_pest Jan 02 '20 at 01:13
  • No need for quoutes, don't forget the *\bin* at the end. – CristiFati Jan 02 '20 at 01:14
  • Well, just done it. Nothing changed :( Thanks anyway, any ideas? – buda_pest Jan 02 '20 at 01:19
  • Without some minimal code (and steps) to reproduce (and some tools versions), no. – CristiFati Jan 02 '20 at 01:20
0

Thank all you guys for the suggestions you gave me

In this answer there is how to find Version.lib in this case.

The following is about accomplishing using GetFileVersionInfoSize(), GetFileVersionInfo() and VerQueryValue() to get the Product Name of an executable file, which is why I needed Version.lib, actually being called libversion.a on my machine.

LAST-EDIT: I managed to achieve what I wanted, this is the code that works in my case:

// filename contains the path of the .exe we want to get Product Name
int version_info_size = GetFileVersionInfoSize(filename, NULL);

if(version_info_size > 0) {
    BYTE *version_info_buffer = new BYTE[version_info_size];

    if(GetFileVersionInfo(filename, 0, version_info_size, version_info_buffer)) {
        char *product_name = NULL;
        UINT pLenFileInfo = 0;

        if(VerQueryValue(version_info_buffer,  TEXT("\\StringFileInfo\\040904e4\\ProductName"),
        (LPVOID*)&product_name, &pLenFileInfo)) cout << product_name;
    }
}

Notice that if you want to compare product_name with another value, you have to do something like string product_name_str = product_name and compare that string variable, otherwise the comparison will always return false. Or maybe just do (string)product_name, I should try.

040904e4 is the lang-code hex translation that I needed in order to do this, I found it thanks to the code in this answer.

buda_pest
  • 46
  • 1
  • 5