c++pdfium

Unable to embed Pdfium - unresolved external symbol


After successfully building Pdfium as per Google's docs, I created a new C++ console app with VS2022 and tried to embed .lib resulting from Pdfium build but, it results in several unresolved symbols which, I guess, should be included in standard C++. As an example, here is two of the unresolved symbols:

fx_string.obj: error LNK2001: unresolved external symbol "void __cdecl std::Cr::__libcpp_verbose_abort(char const *,...)"
fpdf_parser_utility.obj : error LNK2001: unresolved external symbol "public: class std::Cr::basic_ostream<char,struct std::Cr::char_traits<char> > & __cdecl std::Cr::basic_ostream<char,struct std::Cr::char_traits<char> >::write(char const *,__int64)"

Steps taken:

(Unsuccessful) Tests did

Any help is appreciated. Thanks in advance.


Solution

  • After days of failures and (vain) research, I finally found the solution, posted here for future reference.

    TL;DR;

    Depending on flags set in args.gn, Pdfium will need at least the following to successfully build and start the Getting Started example:

    Read also the important note below which tries to explain the difference between the two flags.

    Long description

    As per docs, once .ninja files has been generated as result of gn args <out_dir>, it can be seen which .obj, .lib and .dll files are needed to build pdfium_unitests.exe. Comparing those with the ones used to generate pdfium.lib (or pdfium.dll depending on flags, see below), it can be spotted the required libraries.

    With is_component_build = false and pdf_is_complete_lib = true:

    With is_component_build = true and pdf_is_complete_lib = false:

    Important note

    pdf_is_complete_lib and is_component_build will set, respectively, /MT and /MD flags during compilation.

    Although might not seem a problem, MSBuild will complain if the two types are mixed and thus, you'll need either to recompile Pdfium or change the way your code is generated via Project Properties > C/C++ > Code Generation > Runtime Library.

    For more information see Google docs, Microsoft docs on flags and linker warning and, eventually, this SO question which can help in choose the code generation that most suits your needs.