I am attempting to use ImageMagick to load an image into my C++ application; I'm developing in XCode 7. And I'm struggling. Here is my code.
#include "Magick++.h"
int main(int argc, const char * argv[]) {
Magick::Image img;
return 0;
}
The error that I get follows below.
Ld /Users/ndwork/Library/Developer/Xcode/DerivedData/clsFusion-ghktzemmmuxtfidyywslbqxztyqz/Build/Products/Debug/clsFusion normal x86_64
cd /Users/ndwork/Desktop/clsFusion
export MACOSX_DEPLOYMENT_TARGET=10.11
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -arch x86_64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -L/Users/ndwork/Library/Developer/Xcode/DerivedData/clsFusion-ghktzemmmuxtfidyywslbqxztyqz/Build/Products/Debug -L/opt/X11/lib -F/Users/ndwork/Library/Developer/Xcode/DerivedData/clsFusion-ghktzemmmuxtfidyywslbqxztyqz/Build/Products/Debug -filelist /Users/ndwork/Library/Developer/Xcode/DerivedData/clsFusion-ghktzemmmuxtfidyywslbqxztyqz/Build/Intermediates/clsFusion.build/Debug/clsFusion.build/Objects-normal/x86_64/clsFusion.LinkFileList -mmacosx-version-min=10.11 -Xlinker -no_deduplicate -stdlib=libc++ -lX11.6 -Xlinker -dependency_info -Xlinker /Users/ndwork/Library/Developer/Xcode/DerivedData/clsFusion-ghktzemmmuxtfidyywslbqxztyqz/Build/Intermediates/clsFusion.build/Debug/clsFusion.build/Objects-normal/x86_64/clsFusion_dependency_info.dat -o /Users/ndwork/Library/Developer/Xcode/DerivedData/clsFusion-ghktzemmmuxtfidyywslbqxztyqz/Build/Products/Debug/clsFusion
Undefined symbols for architecture x86_64:
"Magick::Image::Image()", referenced from:
_main in main.o
"Magick::Image::~Image()", referenced from:
_main in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
You can see that I've included the directory where Magick++.h is located in the header search path. I'm not sure how to resolve this. I installed ImageMagick with homebrew.
All help is appreciated!
If you don't have the
homebrew
package calledpkg-config
installed, install that first with:It can then tell you how to compile and link all packages it knows about, so let's see what packages it knows about:
Sample Output
Ok,
Magick++
looks good for you. Let's find the header file path (for#includes
):Sample Output
and the linker flags - which is actually your issue:
Sample Output
Obviously, your values will be different depending on what build-time options you built ImageMagick with - so use your own values, not mine.
Now you just need to put those into Xcode - so click the red-outlined boxes in order and edit in the details you learned above, namely:
You should also define the same defines as suggested by:
Sample Output
in a place that you are happy with.