LNK2019 errors when using a static version of PoDoFo

52 Views Asked by At

Hеllо,

I was wondering if I could request advice on the following issue. I am trying to include a static version of the PoDoFo library, but keep running up against a few LNK2019 errors. Below is an example of the error:

LNK2019 unresolved external symbol "__declspec(dllimport) public: void __cdecl PoDoFo::PdfMemDocument::Load(class std::basic_string_view<char,struct std::char_traits<char> > const &,class std::basic_string_view<char,struct std::char_traits<char> > const &)" (__imp_?Load@PdfMemDocument@PoDoFo@@QEAAXAEBV?$basic_string_view@DU?$char_traits@D@std@@@std@@0@Z) referenced in function wmain Test <path>\main.obj 1

From the looks of it, the linker is trying to add functions from a dynamic library, and for the life of me I cannot understand why it does that.

Below are the particulars on how the PoDoFo library is constructed for the project:

  • The version of the PoDoFo used is the master one from GitHub;
  • The dependencies are from the set provided on GitHub;
  • The library's binary was generated with the parameter PODOFO_BUILD_STATIC set to TRUE;
  • The version used is MinSizeRel (the release version of the minimum size);
  • The main CMakeLists file was altered along the lines of the answer provided here;
  • I am using the current version of the Visual Studio and the ISO C++ 2020 standard;

Below is the code of a test programme calling the library and some of its classes and methods:

// Static library switch
#ifndef PODOFO_STATIC
#define PODOFO_STATIC
#endif // !USING_SHARED_PODOFO

#include "..\..\external\PoDoFo\headers\PoDoFo\podofo.h"

int wmain(int argc, wchar_t* argv[])
{
    PoDoFo::PdfMemDocument pdfIn;
    PoDoFo::PdfMemDocument pdfOut;

    pdfIn.Load("aaa123.pdf");
    pdfOut.Load("bbb123.pdf");

    pdfOut.GetPages().AppendDocumentPages(pdfIn);
    pdfOut.Save("new.pdf");

    _getwch();
}

Of note is the undefined macro USING_SHARED_PODOFO which is required for using a static version of the library.

Apart from undefining the USING_SHARED_PODOFO macro, I also have attempted defining PODOFO_NO_DLL as per one suggestion, but that has not helped either.

UPDATE:

Defining the macro PODOFO_STATIC has resolved the errors above, but produced new ones! They all seem to pertain to various functions defined in PoDoFo's dependencies. A typical example is below (this one comes from openssl):

Error LNK2019 unresolved external symbol EVP_MD_CTX_new referenced in function "public: static void __cdecl PoDoFo::PdfEncryptMD5Base::GetMD5Binary(unsigned char const *,unsigned int,unsigned char *)" (?GetMD5Binary@PdfEncryptMD5Base@PoDoFo@@SAXPEBEIPEAE@Z) Test  <path>\Test\podofo.lib(PdfEncrypt.cpp.obj) 1

Would you happen to have any suggestions on how these can be resolved?

0

There are 0 best solutions below