Linking ImageMagick++ to xCode

Hi all!

I’ve been trying to link ImageMagick into Xcode for few days already. No success.

Following this old thread and googling I came up with the following set up:


I’m using an EmptyExample with OF 0.8.4

I’ve set Macports build_arch i386 flag on /opt/local/etc/macports/macports.conf
I’ve set Macports +universal flag on /opt/local/etc/macports/variants.conf

In the terminal: sudo port install imagemagick +universal All good, no errors.
I’m able to use ImageMagick from the terminal.

On Xcode > Build Settings > Linking > Other Linker Flags
/opt/local/lib/libMagick+±6.Q16.5.dylib
/opt/local/lib/libMagick+±6.Q16.a
/opt/local/lib/libMagickCore-6.Q16.2.dylib
/opt/local/lib/libMagickCore-6.Q16.a
/opt/local/lib/libMagickWand-6.Q16.2.dylib
/opt/local/lib/libMagickWand-6.Q16.a

On Xcode > Build Settings > Search Paths > Header Search Paths:
/opt/local/include/ImageMagick-6 (recursive)
/opt/local/include

On Xcode > Build Settings > Search Paths > Library Search Paths
/opt/local/lib

On the src folder I’ve added:
/opt/local/include/ImageMagick-6

In offApp.h all I’ve added is the header. Just doing this it compiles fine.

#include "Magick++.h"

But, if I try to initialize and Image on ofApp.cpp like this:

Image::Image("someFile.gif");

I get the following error

Undefined symbols for architecture i386:
  "Magick::Image::Image(std::string const&)", referenced from:
      ofApp::setup() in ofApp.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I’ve googled the error and I’ve found several people with the same problem, but not a single response on how to fix it.

I’m pretty igonorant in how all the libraries thing works. I’m sure I’m linking it wrong. I’ve tried putting libraries in diffrent places but nothing seems to work.

Does anyone had any success with ImageMagick? Any idea?

Thanks in advance.

"ld: symbol(s) not found for architecture i386"

this means that ImageMagick is compiled as 64 bit still. I have seen this happen with package managers (like Macports/Homebrew) where the 32bit or Universal option just fails silently/ ignores the request.

from the terminal - what does the output of this command say?

$ file /opt/local/lib/libMagick++-6.Q16.a

@jvcleave thanks for the fast response! :smile:

I’m getting this

/opt/local/lib/libMagick++-6.Q16.a: Mach-O universal binary with 2 architectures
/opt/local/lib/libMagick++-6.Q16.a (for architecture x86_64):	current ar archive random library
/opt/local/lib/libMagick++-6.Q16.a (for architecture i386):	current ar archive random library

@jvcleave, any sugestions on where to go from here?

I would try messing with the the library link order

so maybe

/opt/local/lib/libMagickWand-6.Q16.2.dylib
/opt/local/lib/libMagick++-6.Q16.5.dylib
/opt/local/lib/libMagickCore-6.Q16.2.dylib

That’s one other thing - you seem to be including both the dynamic (.dylib) and static (.a) libs - this may be ok to the compiler (it probably just picks one) but will be harder to troubleshoot

Hi @jvcleave,

I’ve tried all 6 permutations of (.dylib). Cleaning the project everyt time.
I always get the same error as before:

Undefined symbols for architecture i386:
  "Magick::Image::Image(std::string const&)", referenced from:
      ofApp::setup() in ofApp.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I tried also all the combinations with the (.a) libraries. Got the following errors everytime.

Undefined symbols for architecture i386:
  "_XFreeCursor", referenced from:
      _DestroyXResources in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-xwindow.o)
  "_XDestroyWindow", referenced from:
      _DestroyXResources in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-xwindow.o)
     (maybe you meant: _XDestroyWindowColors)
  "_XFreeGC", referenced from:
      _DestroyXResources in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-xwindow.o)
  "_XFreeFont", referenced from:
      _DestroyXResources in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-xwindow.o)
  "_XFree", referenced from:
      _DestroyXResources in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-xwindow.o)
     (maybe you meant: _XFreeResources, _XFreeStandardColormap )
  "_XWithdrawWindow", referenced from:
      _DestroyXResources in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-xwindow.o)
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(char const*, unsigned long)", referenced from:
      Magick::formatExceptionMessage(MagickCore::_ExceptionInfo const*) in libMagick++-6.Q16.a(Magick___lib_libMagick___6_Q16_la-Exception.o)
  "_XFreePixmap", referenced from:
      _DestroyXResources in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-xwindow.o)
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      Magick::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libMagick++-6.Q16.a(Magick___lib_libMagick___6_Q16_la-Exception.o)
      Magick::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, Magick::Exception*) in libMagick++-6.Q16.a(Magick___lib_libMagick___6_Q16_la-Exception.o)
  "_lt_dlopen", referenced from:
      _OpenModule in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-module.o)
  "_lt_dlinit", referenced from:
      _IsModuleTreeInstantiated in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-module.o)
  "Magick::Image::Image(std::string const&)", referenced from:
      ofApp::setup() in ofApp.o
  "_cmsGetProfileInfoASCII", referenced from:
      _GetImageProperty in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-property.o)
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(char const*, unsigned long, unsigned long)", referenced from:
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::operator+<char, std::__1::char_traits<char>, std::__1::allocator<char> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const*) in libMagick++-6.Q16.a(Magick___lib_libMagick___6_Q16_la-Image.o)
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::operator+<char, std::__1::char_traits<char>, std::__1::allocator<char> >(char const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libMagick++-6.Q16.a(Magick___lib_libMagick___6_Q16_la-Exception.o)
  "_gztell", referenced from:
      _TellBlob in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-blob.o)
  "_gzseek", referenced from:
      _SeekBlob in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-blob.o)
  "_BZ2_bzread", referenced from:
      _ReadBlob in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-blob.o)
  "_gzread", referenced from:
      _ReadBlob in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-blob.o)
  "_gzgetc", referenced from:
      _ReadBlob in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-blob.o)
  "_lt_dlclose", referenced from:
      _DestroyModuleNode in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-module.o)
  "_lt_dlerror", referenced from:
      _OpenModule in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-module.o)
      _DestroyModuleNode in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-module.o)
  "_gzopen", referenced from:
      _OpenBlob in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-blob.o)
  "_BZ2_bzopen", referenced from:
      _OpenBlob in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-blob.o)
  "_BZ2_bzflush", referenced from:
      _SyncBlob in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-blob.o)
  "_gzflush", referenced from:
      _SyncBlob in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-blob.o)
  "_cmsOpenProfileFromMem", referenced from:
      _GetImageProperty in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-property.o)
  "_gzclose", referenced from:
      _CloseBlob in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-blob.o)
  "_gzerror", referenced from:
      _CloseBlob in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-blob.o)
  "_BZ2_bzerror", referenced from:
      _CloseBlob in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-blob.o)
  "_BZ2_bzclose", referenced from:
      _CloseBlob in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-blob.o)
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::append(char const*, unsigned long)", referenced from:
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::operator+<char, std::__1::char_traits<char>, std::__1::allocator<char> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const*) in libMagick++-6.Q16.a(Magick___lib_libMagick___6_Q16_la-Image.o)
      Magick::formatExceptionMessage(MagickCore::_ExceptionInfo const*) in libMagick++-6.Q16.a(Magick___lib_libMagick___6_Q16_la-Exception.o)
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::operator+<char, std::__1::char_traits<char>, std::__1::allocator<char> >(char const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libMagick++-6.Q16.a(Magick___lib_libMagick___6_Q16_la-Exception.o)
  "_cmsCloseProfile", referenced from:
      _GetImageProperty in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-property.o)
  "_lt_dlsym", referenced from:
      _OpenModule in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-module.o)
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()", referenced from:
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::operator+<char, std::__1::char_traits<char>, std::__1::allocator<char> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const*) in libMagick++-6.Q16.a(Magick___lib_libMagick___6_Q16_la-Image.o)
      Magick::Exception::~Exception() in libMagick++-6.Q16.a(Magick___lib_libMagick___6_Q16_la-Exception.o)
      Magick::formatExceptionMessage(MagickCore::_ExceptionInfo const*) in libMagick++-6.Q16.a(Magick___lib_libMagick___6_Q16_la-Exception.o)
      Magick::createException(MagickCore::_ExceptionInfo const*) in libMagick++-6.Q16.a(Magick___lib_libMagick___6_Q16_la-Exception.o)
      Magick::throwException(MagickCore::_ExceptionInfo*) in libMagick++-6.Q16.a(Magick___lib_libMagick___6_Q16_la-Exception.o)
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::operator+<char, std::__1::char_traits<char>, std::__1::allocator<char> >(char const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libMagick++-6.Q16.a(Magick___lib_libMagick___6_Q16_la-Exception.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

After some googleing of the previous error someone suggested to install ImageMagick without the X11 dependencies.

Using the +no_x11 flag didn’t do anything an MacPorts keep compiling with x11.
I find out that this is depercated for ImageMagick

So, I’ve downgraded ImageMagick to @6.8.9-1_0 (last version that supports +no_x11) and then installed it again using the +no_x11 and +universal flag.
Got this following errors:

Undefined symbols for architecture i386:
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(char const*, unsigned long)", referenced from:
      Magick::formatExceptionMessage(MagickCore::_ExceptionInfo const*) in libMagick++-6.Q16.a(Exception.o)
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
      Magick::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libMagick++-6.Q16.a(Exception.o)
      Magick::Exception::Exception(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, Magick::Exception*) in libMagick++-6.Q16.a(Exception.o)
  "_lt_dlopen", referenced from:
      _OpenModule in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-module.o)
  "_lt_dlinit", referenced from:
      _IsModuleTreeInstantiated in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-module.o)
  "Magick::Image::Image(std::string const&)", referenced from:
      ofApp::setup() in ofApp.o
  "_cmsGetProfileInfoASCII", referenced from:
      _GetImageProperty in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-property.o)
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(char const*, unsigned long, unsigned long)", referenced from:
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::operator+<char, std::__1::char_traits<char>, std::__1::allocator<char> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const*) in libMagick++-6.Q16.a(Image.o)
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::operator+<char, std::__1::char_traits<char>, std::__1::allocator<char> >(char const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libMagick++-6.Q16.a(Exception.o)
  "_gztell", referenced from:
      _TellBlob in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-blob.o)
  "_gzseek", referenced from:
      _SeekBlob in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-blob.o)
  "_BZ2_bzread", referenced from:
      _ReadBlob in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-blob.o)
  "_gzread", referenced from:
      _ReadBlob in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-blob.o)
  "_gzgetc", referenced from:
      _ReadBlob in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-blob.o)
  "_lt_dlclose", referenced from:
      _DestroyModuleNode in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-module.o)
  "_lt_dlerror", referenced from:
      _OpenModule in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-module.o)
      _DestroyModuleNode in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-module.o)
  "_gzopen", referenced from:
      _OpenBlob in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-blob.o)
  "_BZ2_bzopen", referenced from:
      _OpenBlob in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-blob.o)
  "_BZ2_bzflush", referenced from:
      _SyncBlob in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-blob.o)
  "_gzflush", referenced from:
      _SyncBlob in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-blob.o)
  "_cmsOpenProfileFromMem", referenced from:
      _GetImageProperty in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-property.o)
  "_gzclose", referenced from:
      _CloseBlob in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-blob.o)
  "_gzerror", referenced from:
      _CloseBlob in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-blob.o)
  "_BZ2_bzerror", referenced from:
      _CloseBlob in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-blob.o)
  "_BZ2_bzclose", referenced from:
      _CloseBlob in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-blob.o)
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::append(char const*, unsigned long)", referenced from:
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::operator+<char, std::__1::char_traits<char>, std::__1::allocator<char> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const*) in libMagick++-6.Q16.a(Image.o)
      Magick::formatExceptionMessage(MagickCore::_ExceptionInfo const*) in libMagick++-6.Q16.a(Exception.o)
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::operator+<char, std::__1::char_traits<char>, std::__1::allocator<char> >(char const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libMagick++-6.Q16.a(Exception.o)
  "_cmsCloseProfile", referenced from:
      _GetImageProperty in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-property.o)
  "_lt_dlsym", referenced from:
      _OpenModule in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-module.o)
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()", referenced from:
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::operator+<char, std::__1::char_traits<char>, std::__1::allocator<char> >(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, char const*) in libMagick++-6.Q16.a(Image.o)
      Magick::Exception::~Exception() in libMagick++-6.Q16.a(Exception.o)
      Magick::formatExceptionMessage(MagickCore::_ExceptionInfo const*) in libMagick++-6.Q16.a(Exception.o)
      Magick::createException(MagickCore::_ExceptionInfo const*) in libMagick++-6.Q16.a(Exception.o)
      Magick::throwException(MagickCore::_ExceptionInfo&) in libMagick++-6.Q16.a(Exception.o)
      std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > std::__1::operator+<char, std::__1::char_traits<char>, std::__1::allocator<char> >(char const*, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libMagick++-6.Q16.a(Exception.o)
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

If instead of using the (.a) libreries i use (.dylib) I get again the original error:

Undefined symbols for architecture i386:
  "Magick::Image::Image(std::string const&)", referenced from:
      ofApp::setup() in ofApp.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Any clue?

Thanks.

Basically where it says stuff like

"_lt_dlopen", referenced from:
      _OpenModule in libMagickCore-6.Q16.a(magick_libMagickCore_6_Q16_la-module.o)

It means it is missing a library that ImageMagick is looking for.

It is a lot of searching and Xcode doesn’t make it any easier - typically what I try and do is find a simpler Xcode project that does compile by itself using the library and then start comparing.

I end up giving up on this.
Thanks @jvcleave.

This is probably too late by now but I had the same problem when trying to make Qt work with ImageMagick.
I managed to solve it by setting the right CONFIG value for Qt.

The problem is down to the C++ libraries that are being used. With ImageMagick using libc++ which is standard on Mavericks, and Qt was using libstdc++.

So if you are using Qt all you need to do is make sure you set the CONFIG variable to have c++11 added:
CONFIG += c++11
[Also for those others in Qt land I had to set the following defines to stop compiler warnings:
QMAKE_CXXFLAGS += -DMAGICKCORE_HDRI_ENABLE=0 -DMAGICKCORE_QUANTUM_DEPTH=16
Was using Qt 5.3]

If you are using the compiler then make sure you use the “-std=c++11” switch to the compiler invocation.

I confirmed this by looking at this post on macports:
https://trac.macports.org/ticket/40993

Hope this helps.

1 Like