Project

General

Profile

Undefined Reference Error When Using PDF Renderer Example

Added by Josh Lampco over 11 years ago

I am trying to generate PDF's using the libHARU library in conjunction with the Wt Web Toolkit. I am trying to build example code that is provided Wt Widget Gallery (Wt PDF Renderer) that exports a PDF from XHTML.

I am compiling using g (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 without C++11 features enabled.

The errors that I am getting are as follows:

In function `ReportResource::renderPdf(Wt::WString const&, _HPDF_Doc_Rec*)':
undefined reference to `Wt::Render::WPdfRenderer::WPdfRenderer(_HPDF_Doc_Rec*, _HPDF_Dict_Rec*)'
undefined reference to `Wt::Render::WPdfRenderer::setMargin(double, Wt::WFlags<Wt::Side>)'
undefined reference to `Wt::Render::WPdfRenderer::setDpi(int)'
undefined reference to `Wt::Render::WPdfRenderer::~WPdfRenderer()'
undefined reference to `Wt::Render::WPdfRenderer::~WPdfRenderer()' 

I do not understand the reason for this error as I have built and linked the libHARU library and Wt library into my project. Just as a sanity check - In Eclipse IDE, I can right click on the Wt::Render::WPdfRenderer::WPdfRenderer and open the declaration (if you are familiar with the Eclipse IDE) and Eclipse takes me right to the header file for this class. In other words, I can confirm that WpdfRenderer is definitely defined. What is causing the "undefined reference errors"?

Below is the code I am using - just for reference. Like I said it is taken straight from the Widget Gallery example.

namespace {
    void error_handler(HPDF_STATUS error_no, HPDF_STATUS detail_no, void *user_data) {
    fprintf(stderr, "libharu error: error_no=%04X, detail_no=%d\n", 
              (unsigned int) error_no, (int) detail_no);
    }
}

class ReportResource : public Wt::WResource
{

    public:
        ReportResource(Wt::WObject *parent = 0)
        : Wt::WResource(parent)
        {
            suggestFileName("cycle-times.pdf");
        }

        virtual void handleRequest(const Wt::Http::Request& request,
                                   Wt::Http::Response& response)
        {
            response.setMimeType("application/pdf");

        HPDF_Doc pdf = HPDF_New(error_handler, 0);

        // Note: UTF-8 encoding (for TrueType fonts) is only available since libharu 2.3.0 !
        HPDF_UseUTFEncodings(pdf);

        renderReport(pdf);

        HPDF_SaveToStream(pdf);
        unsigned int size = HPDF_GetStreamSize(pdf);
        HPDF_BYTE *buf = new HPDF_BYTE[size];
        HPDF_ReadFromStream (pdf, buf, &size);
        HPDF_Free(pdf);
        response.out().write((char*)buf, size);
        delete[] buf;
        }

    private:
        void renderReport(HPDF_Doc pdf) {
            renderPdf(Wt::WString::tr("report.example"), pdf);
        }

        void renderPdf(const Wt::WString& html, HPDF_Doc pdf)
        {
        HPDF_Page page = HPDF_AddPage(pdf);
        HPDF_Page_SetSize(page, HPDF_PAGE_SIZE_A4, HPDF_PAGE_PORTRAIT);

        Wt::Render::WPdfRenderer renderer(pdf, page);                                            //The first error occurs at this line.

        renderer.setMargin(2.54);
        renderer.setDpi(96);
        renderer.render(html);
        }
    };

Replies (3)

RE: Undefined Reference Error When Using PDF Renderer Example - Added by Koen Deforche over 11 years ago

Hey,

It seems that you built Wt without libharu support: there will be a message related to not finding libharu when configuring Wt.

Regards,

koen

RE: Undefined Reference Error When Using PDF Renderer Example - Added by Josh Lampco over 11 years ago

Koen,

Yes that does seem to be the case and I do see libharu libraries not found - set HARU_PREFIX after running cmake ../ from my build directory. I have libharu installed in /usr/local/lib. Where do I set the flag for Wt to pick up the libharu libraries? I thought that it should just find them and include them.

Thanks,

Josh

RE: Undefined Reference Error When Using PDF Renderer Example - Added by Wim Dumon over 11 years ago

Run cmake .. -DHARU_PREFIX=/usr/local/

If that does not work, look in CMakeCache.txt to see what was found and what was not found (e.g. headers vs libraries), then check wt/cmake/WtFindHaru.txt to see how Wt checks for these files.

Best regards,

Wim.

    (1-3/3)