Page 1 of 1

Using pkgconfig to find library

Posted: 2013-03-18T09:03:37-07:00
by opoplawski
Couple issues:

- The new library naming scheme presents some difficulties for cmake in finding the library to link to as it does not just use pkgconfig (since it supports platforms without it). Perhaps the pkgconfig file could provide a libname variable that would contain the name? Not sure if there is a standard pkgconfig variable for this.

- Unless the IM headers reference functions in libm, it should not specify it on the link line unless linking privately. Also, wouldn't have to come *after* the ImageMagick library?

This handles these issues:

Code: Select all

--- ImageMagick-6.8.3-9/magick/MagickCore.pc.in.libnam  2013-03-04 10:43:46.000000000 -0700
+++ ImageMagick-6.8.3-9/magick/MagickCore.pc.in 2013-03-18 09:58:48.154429878 -0600
@@ -2,9 +2,11 @@
 exec_prefix=@exec_prefix@
 libdir=@libdir@
 includedir=@includedir@/ImageMagick-@MAGICK_MAJOR_VERSION@
+libname=MagickCore-@MAGICK_MAJOR_VERSION@.@MAGICK_ABI_SUFFIX@
 
 Name: MagickCore
 Description: MagickCore - C API for ImageMagick (ABI @MAGICK_ABI_SUFFIX@)
 Version: @PACKAGE_VERSION@
-Libs: -L${libdir} @MATH_LIBS@ -lMagickCore-@MAGICK_MAJOR_VERSION@.@MAGICK_ABI_SUFFIX@
+Libs: -L${libdir} -l${libname}
+Libs.private: -L${libdir} -l${libname} @MATH_LIBS@
 Cflags: -I${includedir} @MAGICK_PCFLAGS@

Code: Select all

# pkg-config MagickCore --libs
-lMagickCore-6.Q16  
# pkg-config MagickCore --libs --static
-lMagickCore-6.Q16 -lm
# pkg-config MagickCore --variable=libname
MagickCore-6.Q16
Finally, any suggestions for determining the library name on Windows?

Re: Using pkgconfig to find library

Posted: 2013-03-18T09:32:12-07:00
by opoplawski
Another possibility, if your are willing to become CMake-aware you could provide a package
configuration file:

http://www.cmake.org/Wiki/CMake/Tutorials/Packaging

even if you don't build with CMake. That would allow find_package to work even
without a find module.

Qt5 does this for example.

Re: Using pkgconfig to find library

Posted: 2013-03-18T09:33:36-07:00
by magick
Thanks, we'll get these patches into the next point release of ImageMagick.

Re: Using pkgconfig to find library

Posted: 2013-03-21T14:06:36-07:00
by broucaries
Thanks for the patch