Bug 26442 - [cmake] poppler-0.12.3 fails to compile glib component when gtk was found
Summary: [cmake] poppler-0.12.3 fails to compile glib component when gtk was found
Status: RESOLVED FIXED
Alias: None
Product: poppler
Classification: Unclassified
Component: glib frontend (show other bugs)
Version: unspecified
Hardware: All Mac OS X (All)
: medium normal
Assignee: poppler-bugs
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-02-05 01:59 UTC by Fabian Groffen
Modified: 2010-03-20 09:54 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments
darwin gtk link fix (403 bytes, patch)
2010-02-05 01:59 UTC, Fabian Groffen
Details | Splinter Review
build.log (10.10 KB, application/octet-stream)
2010-03-20 05:54 UTC, Fabian Groffen
Details
Check for existing link flags (2.10 KB, patch)
2010-03-20 07:09 UTC, Pino Toscano
Details | Splinter Review

Description Fabian Groffen 2010-02-05 01:59:43 UTC
Created attachment 33091 [details] [review]
darwin gtk link fix

Using the Cmake way to build.
The full error is multiple pages long, but this gives the idea:

Linking CXX shared library libpoppler-glib.dylib
ld warning: duplicate dylib /Library/Gentoo/lib/libz.dylib
Undefined symbols:
  "_g_type_class_add_private", referenced from:
      poppler_attachment_class_init(_PopplerAttachmentClass*)       in poppler-attachment.cc.o
  "_g_value_set_flags", referenced from:
      poppler_document_get_property(_GObject*, unsigned int, _GValue*, _GParamSpec*)in poppler-document.cc.o
      poppler_document_get_property(_GObject*, unsigned int, _GValue*, _GParamSpec*)in poppler-document.cc.o
  "_g_type_check_instance_is_a", referenced from:
      _poppler_ps_file_new in poppler-document.cc.o
      _poppler_document_has_attachments in poppler-document.cc.o
      _poppler_document_get_n_pages in poppler-document.cc.o
      _poppler_font_info_new in poppler-document.cc.o


The _g_XXX symbols come from gtk, which libraries are not given to the linker when GTK is found.  I will attach a patch which fixes this for me.
Comment 1 Albert Astals Cid 2010-02-06 07:38:41 UTC
g_value_set_flags does not come from gtk, it comes from glib and we are already linking in glib, do your system is broken i'd say
Comment 2 Fabian Groffen 2010-02-06 09:40:33 UTC
% nm usr/lib/libglib-2.0.dylib  | grep g_value_set_flags
% nm usr/lib/libgobject-2.0.dylib  | grep g_value_set_flags
00021d23 T _g_value_set_flags
%

gtk uses this symbol, and also properly links against libgobject.  Since the problem only occurs when a GTK build is enabled, and the symbol can be found when the gtk libs are used, it felt like a logical fix to me.

Notice that the Darwin linker is stricter in this respect than GNU binutils.

I checked on Solaris, and couldn't find the g_value_set_flags symbol in the libglib-2.0.so library either.
Comment 3 Albert Astals Cid 2010-02-06 10:49:15 UTC
Two questions:
 * Does the autotools based build work?
 * Does this patch help?

diff --git a/glib/CMakeLists.txt b/glib/CMakeLists.txt
index 6ed9523..392da66 100644
--- a/glib/CMakeLists.txt
+++ b/glib/CMakeLists.txt
@@ -112,6 +112,7 @@ if (GDK_FOUND)
     test-poppler-glib.cc
   )
   poppler_add_test(test-poppler-glib BUILD_GTK_TESTS ${test_poppler_glib_SRCS})
+  target_link_libraries(poppler-glib ${GDK2_LIBRARIES})
   target_link_libraries(test-poppler-glib poppler-glib ${GDK2_LIBRARIES})
 endif (GDK_FOUND)

Comment 4 Fabian Groffen 2010-02-07 01:48:55 UTC
(In reply to comment #3)
> Two questions:
>  * Does the autotools based build work?

Yes, it seems to use the GTK libs when linking, resulting in a successful compile.

>  * Does this patch help?
> 
> diff --git a/glib/CMakeLists.txt b/glib/CMakeLists.txt
> index 6ed9523..392da66 100644
> --- a/glib/CMakeLists.txt
> +++ b/glib/CMakeLists.txt
> @@ -112,6 +112,7 @@ if (GDK_FOUND)
>      test-poppler-glib.cc
>    )
>    poppler_add_test(test-poppler-glib BUILD_GTK_TESTS
> ${test_poppler_glib_SRCS})
> +  target_link_libraries(poppler-glib ${GDK2_LIBRARIES})
>    target_link_libraries(test-poppler-glib poppler-glib ${GDK2_LIBRARIES})
>  endif (GDK_FOUND)
> 

No, it fails in the same way as before.
Comment 5 Albert Astals Cid 2010-02-09 15:12:09 UTC
/bin/bash ../libtool  --tag=CXX   --mode=link g++  -Wall -Wno-write-strings -Woverloaded-virtual -Wnon-virtual-dtor -ansi -g -O2 -version-info 4:0:0    -o libpoppler-glib.la -rpath /usr/local/lib poppler-enums.lo poppler-action.lo poppler-date.lo poppler-document.lo poppler-page.lo poppler-attachment.lo poppler-form-field.lo poppler-annot.lo poppler-layer.lo poppler.lo ../poppler/libpoppler.la ../poppler/libpoppler-cairo.la -lgobject-2.0 -lglib-2.0 -lcairo   -lgdk-x11-2.0 -lgdk_pixbuf-2.0 -lm -lpangocairo-1.0 -lgio-2.0 -lpango-1.0 -lcairo -lgobject-2.0 -lgmodule-2.0 -lglib-2.0   -lfreetype   -lfontconfig

I don't see any GTK lib here

Can you post your autotools link line?
Comment 6 Fabian Groffen 2010-02-10 00:34:27 UTC
You have -lgobject-2.0, which has the required symbols.  I don't have a compilation at hand, but I'd assume about the same libs to be there.

I know that once GTK is enabled in the cmake build, it fails like this.  Maybe GTK is the wrong word here and should it be GDK or something else instead.  I haven't examined the code in detail (yet).
Comment 7 Albert Astals Cid 2010-02-11 12:43:26 UTC
Well, ${GDK2_LIBRARIES} has gobject for me so my patch "works for me", if it doesn't for you, you need to work a bit more on this.
Comment 8 Fabian Groffen 2010-02-13 02:34:24 UTC
If I change my patch to use FOUND_GDK and GDK2_LIBRARIES instead of FOUND_GTK and GTK2_LIBRARIES it works still fine for me.  Your patch somehow doesn't seem to reach the right linkline for the glib component, whereas mine does.
Comment 9 Albert Astals Cid 2010-02-16 15:13:50 UTC
Wait, i just realized you are using 0.12.3, any chance you can try git master branch (with and without my patch)
Comment 10 Pino Toscano 2010-03-17 09:06:47 UTC
Recently (after the 0.13.1 release) I did various improvements on the CMake build system. Can you try an unpatched compilation of master (or of poppler 0.13.2, when it is released)?
Comment 11 Fabian Groffen 2010-03-20 04:47:09 UTC
using CMake 2.8.1, git master branch of as of say an hour ago:

...
[ 41%] Building CXX object utils/CMakeFiles/pdftoabw.dir/pdftoabw.cc.o
Linking CXX executable pdftoabw
Undefined symbols:
  "_xmlSaveFormatFileEnc", referenced from:
      _main in pdftoabw.cc.o
  "_xmlFreeDoc", referenced from:
      _main in pdftoabw.cc.o
  "_xmlNewDoc", referenced from:
      _main in pdftoabw.cc.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

probably missing -lxml2, so I disabled abiword support:

[ 54%] Building CXX object glib/CMakeFiles/poppler-glib.dir/__/poppler/CairoRescaleBox.cc.o
Linking CXX shared library libpoppler-glib.dylib
Undefined symbols:
  "_FT_Done_Face", referenced from:
      _ft_done_face(void*)  in CairoFontEngine.cc.o
      _ft_done_face_uncached(void*)  in CairoFontEngine.cc.o
  "_FT_New_Face", referenced from:
      _ft_new_face_uncached(FT_LibraryRec_*, char const*, char*, int, FT_FaceRec_**, _cairo_font_face**)in CairoFontEngine.cc.o
  "_FT_Init_FreeType", referenced from:
      CairoOutputDev::CairoOutputDev()in CairoOutputDev.cc.o
  "_FT_New_Memory_Face", referenced from:
      _ft_new_face_uncached(FT_LibraryRec_*, char const*, char*, int, FT_FaceRec_**, _cairo_font_face**)in CairoFontEngine.cc.o
      _ft_new_face(FT_LibraryRec_*, char const*, char*, int, FT_FaceRec_**, _cairo_font_face**)in CairoFontEngine.cc.o
  "_FT_Library_Version", referenced from:
      CairoFontEngine::CairoFontEngine(FT_LibraryRec_*)in CairoFontEngine.cc.o
  "_FT_Get_Name_Index", referenced from:
      CairoFreeTypeFont::create(GfxFont*, XRef*, FT_LibraryRec_*, int) in CairoFontEngine.cc.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

yay!  probably missing -lfreetype

autoconf really isn't that bad guys :/
Comment 12 Pino Toscano 2010-03-20 05:05:14 UTC
I can reproduce the link issue (though with another error message) of pdftoabw but not poppler-glib.

Can you provide (at attachment) a build log done with `make -k VERBOSE=1`? Thanks
Comment 13 Fabian Groffen 2010-03-20 05:54:58 UTC
Created attachment 34254 [details]
build.log

here it is
Comment 14 Pino Toscano 2010-03-20 06:14:53 UTC
Very useful, thanks.
I pushed to master few commits which should fix the issues you faced, can you please test again?

Thanks again
Comment 15 Fabian Groffen 2010-03-20 06:20:24 UTC
Linking CXX shared library libpoppler.dylib
ld: unknown option: --as-needed

I think you should revert your --as-needed git-commit as it's going to break more platforms.  Better try to configure if it is supported by the linker, and only then use it, if you really want to.
Comment 16 Pino Toscano 2010-03-20 07:09:16 UTC
Created attachment 34255 [details] [review]
Check for existing link flags

Can you please try this patch, and paste what cmake outputs for
-- Performing Test GCC_HAS_AS_NEEDED                                                                                                                    
and
-- Performing Test GCC_HAS_NO_ADD_NEEDED                                                                                                                
?
Comment 17 Fabian Groffen 2010-03-20 09:48:15 UTC
-- Performing Test GCC_HAS_AS_NEEDED
-- Performing Test GCC_HAS_AS_NEEDED - Failed
-- Performing Test GCC_HAS_NO_ADD_NEEDED
-- Performing Test GCC_HAS_NO_ADD_NEEDED - Failed

Linking now succeeds, thanks!
Comment 18 Pino Toscano 2010-03-20 09:54:09 UTC
Pushed the patch to master, thanks for the report and the testing!


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.