0

I'm pretty new to vcpkg, but it seems like a handy tool. However, it doesn't seem to help me overcome the normal-for-me linking issues as hoped/promised. I'm trying to use GDCM in a visual studio project, but get LNK2019 errors.

When installing the GDCM package with vcpkg, one of the output messages states that GDCM can only be statically linked, so I have explicitly installed gdcm:x64-windows-static

I successfully followed the example for static linking found at: https://levelup.gitconnected.com/how-to-statically-link-c-libraries-with-vcpkg-visual-studio-2019-435c2d4ace03.

Extending that example to include some GDCM functions;

int main()
{
    spdlog::info("Hello Static Linking!");

    gdcm::Reader file_reader;

    const char* filename =C:\\file_path_and_name\\of\\dicom\\file.dcm";

    file_reader.SetFileName(filename);
    if (!file_reader.Read()) {
        std::cout << filename << "doesn't look like DICOM" << '\n';
    } else {
        std::cout << "success reading" << filename << '\n';
    }

}

leads to LNK2019 errors

Error   LNK2019 unresolved external symbol gethostname referenced in function "public: static bool __cdecl gdcm::System::GetHostName(char * const)" (?GetHostName@System@gdcm@@SA_NQEAD@Z)  DemoStaticLinking   C:\Users\...\gdcmCommon.lib(gdcmSystem.cxx.obj) 1

What am I doing wrong? I thought/hoped vcpkg would help me overcome these kinds of issues!

Update: Looking more into the error the link errors relate to functions within gdcm itself - however no error was returned when vcpkg was building and installing the library.

I managed to get the code to run firstly by building GDCM from source and manually setting up the static libraries to link in Visual studio, including the one related to this link error (Ws2_32.lib) that GDCM then wants, and then using the automatic linking of the package in vcpkg but manually adding the link to Ws2_32.lib in VS.

To refine my question a bit... isn't the idea of vcpkg that I should have to find such libraries to link? shouldn't they be included by the package manager as a dependence?

  • [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Jesper Juhl Dec 07 '22 at 15:18
  • ***https://learn.microsoft.com/en-us/windows/win32/api/winsock/nf-winsock-gethostname*** From the msdn documentation you need to link to `Ws2_32.lib` – drescherjm Dec 07 '22 at 16:33
  • You ran into the problem here because the building of static linking of gdcm did not combine the windows dependent library (winsock) into the static gdcm library. If you had used gdcm shared library (dll release) this dependency would have been internal to the dll. – drescherjm Dec 07 '22 at 16:52
  • thanks drescherjm. I made some progress in that direction. vcpkg doesn't seem to give the option of the shared library for this package. – DrDiagnosis Dec 07 '22 at 17:53
  • It's surprising that `const char* filename =C:\\file_path_and_name\\of\\dicom\\file.dcm";` compiles. It doesn't for me. – Ted Lyngmo Dec 08 '22 at 20:01
  • @TedLyngmo he he. Obviously that was a toy example, and I missed the quote. – DrDiagnosis Dec 09 '22 at 14:17

0 Answers0