0

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?

NDC
  • 21
  • 2
  • 2
    your defines need to be before rather than after the include – Alan Birtles Apr 21 '23 at 18:49
  • Thank you for pointing this out, @AlanBirtles. The problem still stands though. – NDC Apr 21 '23 at 18:55
  • The `__declspec(dllimport)` part means it's looking for an import library (.lib) that comes with a dll. – drescherjm Apr 21 '23 at 19:12
  • Yes, @drescherjm, that is what I mentioned too: «From the looks of it, the linker is trying to add functions from a dynamic library», - but I just cannot see at all why that is happening. – NDC Apr 21 '23 at 19:20
  • 1
    https://github.com/podofo/podofo/blob/535a786f124b739e3c857529cecc29e4eeb79778/src/podofo/auxiliary/basedefs.h#L45 – Hans Passant Apr 21 '23 at 19:39
  • From the previous link it looks like `PODOFO_STATIC` needs to be defined. – drescherjm Apr 21 '23 at 20:25
  • Thank you very much, @HansPassant! That kind of worked: the errors are different now! I have updated the question to reflect this. – NDC Apr 21 '23 at 21:41
  • The new error looks like openssl: [https://stackoverflow.com/questions/46768071/openssl-linking-undefined-reference-evp-md-ctx-new-and-fre](https://stackoverflow.com/questions/46768071/openssl-linking-undefined-reference-evp-md-ctx-new-and-fre) One negative to using static libraries is you need to link to all the libs that the static library depends on where you would not have to do that if you used dlls. – drescherjm Apr 21 '23 at 21:49
  • Thank you very much for pointing this out, @drescherjm! That should solve it, I think. – NDC Apr 22 '23 at 18:19

0 Answers0