Using pkgconfig to find library

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
opoplawski
Posts: 5
Joined: 2010-02-05T16:50:16-07:00
Authentication code: 8675309

Using pkgconfig to find library

Post 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?
opoplawski
Posts: 5
Joined: 2010-02-05T16:50:16-07:00
Authentication code: 8675309

Re: Using pkgconfig to find library

Post 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.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Using pkgconfig to find library

Post by magick »

Thanks, we'll get these patches into the next point release of ImageMagick.
broucaries
Posts: 467
Joined: 2008-12-21T11:51:10-07:00

Re: Using pkgconfig to find library

Post by broucaries »

Thanks for the patch
Post Reply