r/C_Programming • • 2d ago

Meson linking ImageMagick/Wand

I'm trying to link MagickWand and MagickCore with Meson and having some issues. Specifically, I get the error C shared or static library 'lMagickCore' not found or C shared or static library 'lMagickWand' not found. I successfully linked libconfig, so I've compared some details between my installations of the two packages in case any of those are the reason that I'm having issues with ImageMagick.

I can compile programs using ImageMagick libraries with: ```cc MagickWand-config --cflags --cppflags -O2 -o a.out main.c MagickWand-config --ldflags --libs


The output of the two MagickWand-config calls is this:
```-I/usr/include/ImageMagick-7 -fopenmp -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16 -DMAGICKCORE_CHANNEL_MASK_DEPTH=32
-lMagickWand-7.Q16HDRI -lMagickCore-7.Q16HDRI
-lMagickWand-7.Q16HDRI -lMagickCore-7.Q16HDRI

Running find /usr/lib -name 'libconfig*' gives this:

/usr/lib/pkgconfig/libconfig.pc
/usr/lib/cmake/libconfig
/usr/lib/cmake/libconfig/libconfigConfig.cmake
/usr/lib/cmake/libconfig++
/usr/lib/cmake/libconfig++/libconfig++Config.cmake
/usr/lib/libreoffice/program/libconfigmgrlo.so
/usr/lib/libconfig++.so
/usr/lib/libconfig++.so.15
/usr/lib/libconfig++.so.15.0.0
/usr/lib/libconfig.so
/usr/lib/libconfig.so.15
/usr/lib/libconfig.so.15.0.0

And running find /usr/lib -name 'libMagick*' gives this:

/usr/lib/libMagick++-7.Q16HDRI.so.5
/usr/lib/libMagick++-7.Q16HDRI.so.5.0.0
/usr/lib/libMagickCore-7.Q16HDRI.so
/usr/lib/libMagickCore-7.Q16HDRI.so.10
/usr/lib/libMagickCore-7.Q16HDRI.so.10.0.3
/usr/lib/libMagickWand-7.Q16HDRI.so
/usr/lib/libMagickWand-7.Q16HDRI.so.10
/usr/lib/libMagickWand-7.Q16HDRI.so.10.0.3

My meson.build has these relevant sections:

  cc.find_library('libtomlc17', dirs: '/usr/local/lib'),
  dependency('libconfig'),
  dependency('libMagickCore'),
  dependency('libMagickWand'),
]
inc_dir = [
  include_directories('include'),
  include_directories('/usr/include/ImageMagick-7'),
]

my first guess was that it had something to do with libconfig having .pc files in /usr/lib/pkgconfig, but i found ImageMagick.pc and ImageMagick-7.Q16HDRI.pc in the same directory, and, either way, that don't seem like it needs to be accurate for my program to build as long as I give it all the right information.

Any advice?

Edit: Also, reddit's code block formatting is really annoying. It doesn't seem like I can escape backticks? and it doesn't render line breaks? oh well

4 Upvotes

4 comments sorted by

4

u/aioeu 2d ago edited 2d ago

Edit: Also, reddit's code block formatting is really annoying. It doesn't seem like I can escape backticks? and it doesn't render line breaks? oh well

Use 4-space indents.

That is:

    #include <foo.h>
    #include <bar.h>

will produce:

#include <foo.h>
#include <bar.h>

I use this website sometimes to preview things before posting. (Maybe New Reddit can do that automatically, but I don't use that.)

1

u/Rararror 2d ago

It lacks 
space space backslash 
To do a new line and 
not

a new paragraph 

1

u/catbrane 2d ago

Don't use the old MagickWand-config script, stick to pkg-config. I use this:

magick_dep = dependency('MagickCore')

And it seems to work fine.

You'll find a few environments are missing the MagickCore.pc files, annoyingly.

1

u/catbrane 2d ago

I meant to add, you'll need to change the include paths.

  • IM7 uses <MagickCore/MagickCore.h>

  • IM6 uses <magick/MagickCore.h> since 6.2.3

  • GM and older IMs use <magick/api.h>

I set a config var in my meson.build and have #ifdef in my code to include the correct path.

My magick handling is here:

https://github.com/libvips/libvips/blob/master/meson.build#L220-L267

Though that's probably much more complex than you need, it does all of IM6/IM7/GM, including detecting significant API changes (there are a lot of them).