Skip to content
This repository has been archived by the owner on Aug 7, 2022. It is now read-only.

compilation error when building epdfinfo program #372

Closed
kirk86 opened this issue Apr 19, 2018 · 22 comments
Closed

compilation error when building epdfinfo program #372

kirk86 opened this issue Apr 19, 2018 · 22 comments

Comments

@kirk86
Copy link

kirk86 commented Apr 19, 2018

Hi I keep getting the following error whenever I try to compile the pdf-tools.

poppler-hack.cc: In function 'void xpoppler_annot_set_rectangle(PopplerAnnot*, PopplerRectangle*)':
poppler-hack.cc:88:49: error: invalid conversion from 'const GooString*' to 'GooString*' [-fpermissive]
     GooString *state = a->annot->getAppearState ();
                        ~~~~~~~~~~~~~~~~~~~~~~~~~^~
poppler-hack.cc: In function 'gchar* xpoppler_annot_markup_get_created(PopplerAnnotMarkup*)':
poppler-hack.cc:108:27: error: invalid conversion from 'const GooString*' to 'GooString*' [-fpermissive]
     text = annot->getDate ();
            ~~~~~~~~~~~~~~~^~
make[1]: *** [epdfinfo-poppler-hack.o] Error 1
make: *** [all] Error 2

I've tried removing completely pdf-tools and re-installing but still I get the same error.
How can we resolve this?

Thanks!

@kirk86 kirk86 changed the title compilation error when building epdfserver compilation error when building epdfinfo program Apr 19, 2018
@ht-hieu
Copy link

ht-hieu commented Apr 24, 2018

Hi, I got this error when building epdfinfo:

poppler-hack.cc: In function ‘char* _xpoppler_goo_string_to_utf8(const GooString*)’:
poppler-hack.cc:61:29: error: passing ‘const GooString’ as ‘this’ argument discards qualifiers [-fpermissive]
     if (s->hasUnicodeMarker()) {
                             ^
In file included from /usr/include/poppler/Object.h:42:0,
                 from /usr/include/poppler/Annot.h:42,
                 from poppler-hack.cc:18:
/usr/include/poppler/goo/GooString.h:163:9: note:   in call to ‘GBool GooString::hasUnicodeMarker()’
   GBool hasUnicodeMarker(void);
         ^
Makefile:552: recipe for target 'epdfinfo-poppler-hack.o' failed
make[1]: *** [epdfinfo-poppler-hack.o] Error 1
Makefile:363: recipe for target 'all' failed
make: *** [all] Error 2

I'm using Ubuntu 16.04 and Emacs 25.1
Thanks.

@edmundmiller
Copy link

+1

@kaz-yos
Copy link

kaz-yos commented Apr 24, 2018

I had the same epdfinfo compilation problem. macOS 10.13.4, Emacs 27.0.50 (2018-04-22), elpa pdf-tools-20180109.1234, Homebrew poppler 0.64.0. Switching back to the old poppler temporarily fixed the compilation issue.

brew switch poppler 0.63.0_1

@et2010
Copy link

et2010 commented Apr 25, 2018

I had the same issue as @gochit , pdf-tools-20180422.935, Linux Mint 18.03, emacs 25.3.1

@dmringo
Copy link

dmringo commented Apr 25, 2018

@gochit @et2010 I had the same problem. It shouldn't be an issue with more recent versions of poppler; hasUnicodeMarker was changed to const in late 2016. As a workaround, you can define the following function in server/poppler-hack.cc:

// Implements the same logic as GooString::hasUnicodeMarker() in poppler 
bool hasUnicodeMarker(const GooString *s) {
  return (s->getChar(0) & 0xff) == 0xfe && (s->getChar(1) & 0xff) == 0xff;
}

and change the call s->hasUnicodeMarker() to hasUnicodeMarker(s).

edited: the second call to getChar above was originally given an argument of 0, but it should be 1. Sorry for the confusion!

@jmburgos
Copy link

@dmringo, updated poppler to 0.64 but I am still having the same issue. Could you share your version of poppler-hack.cc?

@ryw89
Copy link

ryw89 commented Apr 26, 2018

@jmburgos I had the same issue and I found following @dmringo's advice worked for me. Here's my version of poppler-hack.cc. Not knowing anything about C++ I just put the bool bit under extern "C" {. The change from s->hasUnicodeMarker() to hasUnicodeMarker(s) is on line 67. In any case this worked for me.

Edit: Second call of getchar changed from 0 to 1.

// Copyright (C) 2013, 2014  Andreas Politz

// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

#include <config.h>
#include <PDFDocEncoding.h>
#include <Annot.h>
#include <glib.h>
#include <glib-object.h>

extern "C"
{

// Implements the same logic as GooString::hasUnicodeMarker() in poppler 
bool hasUnicodeMarker(const GooString *s) {
  return (s->getChar(0) & 0xff) == 0xfe && (s->getChar(1) & 0xff) == 0xff;
}

  
GType poppler_annot_get_type (void) G_GNUC_CONST;
GType poppler_annot_markup_get_type (void) G_GNUC_CONST;

#define POPPLER_TYPE_ANNOT (poppler_annot_get_type ())
#define POPPLER_ANNOT(obj) \
  (G_TYPE_CHECK_INSTANCE_CAST ((obj), POPPLER_TYPE_ANNOT, PopplerAnnot))
#define POPPLER_IS_ANNOT_MARKUP(obj) \
  (G_TYPE_CHECK_INSTANCE_TYPE ((obj), POPPLER_TYPE_ANNOT_MARKUP))
#define POPPLER_TYPE_ANNOT_MARKUP (poppler_annot_markup_get_type ())

  struct PopplerAnnot
  {
    GObject  parent_instance;
    Annot   *annot;
  };

  struct PopplerAnnotMarkup
  {
    GObject  parent_instance;
  };

  struct PopplerRectangle
  {
    double x1;
    double y1;
    double x2;
    double y2;
  };

  char *_xpoppler_goo_string_to_utf8(const GooString *s)
  {
    char *result;

    if (! s)
      return NULL;

    if (hasUnicodeMarker(s)) {
      result = g_convert (s->getCString () + 2,
                          s->getLength () - 2,
                          "UTF-8", "UTF-16BE", NULL, NULL, NULL);
    } else {
      int len;
      gunichar *ucs4_temp;
      int i;

      len = s->getLength ();
      ucs4_temp = g_new (gunichar, len + 1);
      for (i = 0; i < len; ++i) {
        ucs4_temp[i] = pdfDocEncoding[(unsigned char)s->getChar(i)];
      }
      ucs4_temp[i] = 0;

      result = g_ucs4_to_utf8 (ucs4_temp, -1, NULL, NULL, NULL);
      g_free (ucs4_temp);
    }

    return result;
  }
#ifdef HAVE_POPPLER_ANNOT_WRITE
  // Set the rectangle of an annotation.  It was first added in v0.26.
  void xpoppler_annot_set_rectangle (PopplerAnnot *a, PopplerRectangle *rectangle)
  {
    GooString *state = (GooString *)a->annot->getAppearState ();
    char *ustate = _xpoppler_goo_string_to_utf8 (state);

    a->annot->setRect (rectangle->x1, rectangle->y1,
                       rectangle->x2, rectangle->y2);
    a->annot->setAppearanceState (ustate);
    g_free (ustate);
  }
#endif
  // This function is in the library, but the enforced date parsing is
  // incomplete (at least in some versions), because it ignores the
  // timezone.
  gchar *xpoppler_annot_markup_get_created (PopplerAnnotMarkup *poppler_annot)
  {
    AnnotMarkup *annot;
    const GooString *text;

    g_return_val_if_fail (POPPLER_IS_ANNOT_MARKUP (poppler_annot), NULL);

    annot = static_cast<AnnotMarkup *>(POPPLER_ANNOT (poppler_annot)->annot);
    text = (GooString *)annot->getDate ();

    return text ? _xpoppler_goo_string_to_utf8 (text) : NULL;
  }
}

@jmburgos
Copy link

Thanks @ryw89 . Still having problems though. So basically you replaced the poppler-hack.cc function and then just ran M-x pdf-tools-install, correct? Or I am missing something?

@ryw89
Copy link

ryw89 commented Apr 26, 2018

That's correct @jmburgos. After changing the poppler-hack.cc file running M-x pdf-tools-install did the build successfully for me.

@jmburgos
Copy link

jmburgos commented Apr 26, 2018

Ok, I started from scratch by reinstalling pdftools, and just realized that my error message is a bit different than mentioned before.

poppler-hack.cc: In function ‘char* _xpoppler_goo_string_to_utf8(const GooString*)’:
poppler-hack.cc:61:29: error: passing ‘const GooString’ as ‘this’ argument of ‘GBool GooString::hasUnicodeMarker()’ discards qualifiers [-fpermissive]
     if (s->hasUnicodeMarker()) {
                             ^
poppler-hack.cc:63:41: error: passing ‘const GooString’ as ‘this’ argument of ‘int GooString::getLength()’ discards qualifiers [-fpermissive]
                           s->getLength () - 2,
                                         ^
poppler-hack.cc:70:27: error: passing ‘const GooString’ as ‘this’ argument of ‘int GooString::getLength()’ discards qualifiers [-fpermissive]
       len = s->getLength ();
                           ^
poppler-hack.cc:73:66: error: passing ‘const GooString’ as ‘this’ argument of ‘char GooString::getChar(int)’ discards qualifiers [-fpermissive]
         ucs4_temp[i] = pdfDocEncoding[(unsigned char)s->getChar(i)];

@politza
Copy link
Owner

politza commented Apr 26, 2018

So, the original error is fixed by using the appropriate const modifier in our code. But this introduces new incompatibilities with older poppler-code, because the older code does not mark functions as const even though they are.

Why does the compiler suddenly care about the return value of getAppearState being const anyway, i.e. why are we in this mess ?

@dmringo
Copy link

dmringo commented Apr 26, 2018

@ryw89 I was sloppy in my original snippet, and have since fixed it. Would you update yours to match for any future observers looking to solve the hasUnicodeMarker compilation error? You just need to change the argument of the second call to getChar from 0 to 1.

@jmburgos @gochit @et2010 This may affect you too if you used the original workaround code

@jmburgos
Copy link

Still not working, and I am a bit over my head. I will use zathura until this gets fixed. :)

@politza
Copy link
Owner

politza commented Apr 27, 2018

So, after some investigation I found out that the poppler people made the return value of the methods getAppearanceStream and getDate constant. That's why these errors occur when compiling against recent upstream.

After @peschkaj's proposal to cast the const away, I immediately jumped to the conclusion, that it would be better to change the signature of the function, without really thinking about what's actually happening and what the implications of theses changes would be.

And while it's possible in this world to work around the hasUnicodeMarker method, this doesn't hold for the getLength one (which was made const in around 2015), since it uses private fields.

Lange Rede, kurzer Sinn: I've reverted the change and implemented the originally proposed solution.

I hope that this will work for everyone.

@jmburgos
Copy link

It works like a charm. Thank you!!

@yurist
Copy link

yurist commented Jul 15, 2018

Still the same problem on MacOS, as referenced by @dunn:

poppler-hack.cc:88:16: error: cannot initialize a variable of type 'GooString *' with an rvalue of type 'const GooString *'
    GooString *state = a->annot->getAppearState ();
               ^       ~~~~~~~~~~~~~~~~~~~~~~~~~~~
poppler-hack.cc:108:19: error: assigning to 'GooString *' from incompatible type 'const GooString *'
    text = annot->getDate ();
           ~~~~~~~^~~~~~~~~~
2 errors generated.
make[2]: *** [epdfinfo-poppler-hack.o] Error 1
make[1]: *** [all] Error 2
make: *** [server/epdfinfo] Error 2

@politza
Copy link
Owner

politza commented Jul 15, 2018 via email

@yurist
Copy link

yurist commented Jul 15, 2018

Thanks for the response! Do you have any ETA when it makes it downstream? I might want to spend some time building from master - which shouldn't be a problem, but I will have to integrate it into Emacs then which might take longer, so I wonder if I do it or wait for the fix to reach emacs support,

@yurist
Copy link

yurist commented Jul 16, 2018

Trying to build from master... The tar file was successfully created (after I upgraded to emacs 26.1). Now it fails to install, both within and outside of emacs:

pdf-tools/ (master✗) $ make install-package                                                                                 [18:43:05]
Using Emacs 26.1
make: *** No rule to make target `install-package'.  Stop.

Inside emacs:

Debugger entered--Lisp error: (wrong-type-argument arrayp nil)
  tar--describe-as-link(nil)
  tar--check-descriptor(nil)
  tar-get-file-descriptor("PaxHeader/PaxHeader-pkg.el")
  package-tar-file-info()
  package-install-from-buffer()
  package-install-file("/Users/ysteinschreiber/prvprj/pdf-tools/pdf-tools-0.90.tar")
  funcall-interactively(package-install-file "/Users/ysteinschreiber/prvprj/pdf-tools/pdf-tools-0.90.tar")
  #<subr call-interactively>(package-install-file record nil)
  apply(#<subr call-interactively> package-install-file (record nil))
  call-interactively@ido-cr+-record-current-command(#<subr call-interactively> package-install-file record nil)
  apply(call-interactively@ido-cr+-record-current-command #<subr call-interactively> (package-install-file record nil))
  call-interactively(package-install-file record nil)
  command-execute(package-install-file record)
  helm-M-x(nil #("package-install-file" 0 20 (match-part "package-install-file")))
  funcall-interactively(helm-M-x nil #("package-install-file" 0 20 (match-part "package-install-file")))
  #<subr call-interactively>(helm-M-x nil nil)
  apply(#<subr call-interactively> helm-M-x (nil nil))
  call-interactively@ido-cr+-record-current-command(#<subr call-interactively> helm-M-x nil nil)
  apply(call-interactively@ido-cr+-record-current-command #<subr call-interactively> (helm-M-x nil nil))
  call-interactively(helm-M-x nil nil)
  command-execute(helm-M-x)

nickdrozd added a commit to nickdrozd/.emacs.d that referenced this issue Aug 2, 2018
Some kind of change somewhere was causing build failures on Mac, and
the fix hasn't been released yet.

See politza/pdf-tools#372
@politza
Copy link
Owner

politza commented Sep 24, 2018

Trying to build from master...

Is this still a problem ? Just install from melpa.

@politza
Copy link
Owner

politza commented Oct 26, 2018 via email

@ingolfschaefer
Copy link

Which one? Just post the compiler output.

Sorry, I already delete my comment, since it turned out that there was a file corruption on my hard drive which resulted in a corrupt header file in Poppler. It raised a very similar error, but a reinstall fixed it. Mea culpa. Works fine on Ubuntu 18.04 with the melpa version of pdf-tools now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.