DrDiagnosis
DrDiagnosis

Reputation: 101

Why am I getting LNK2019 errors in visual studio with GDCM and vcpkg

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?

Upvotes: 0

Views: 28

Answers (0)

Related Questions