Undefined symbols for architecture x86_64

2019-08-25 18:42发布

问题:

I am trying to use imagemagick in Xcode, and I am getting this error :

Ld /Users/sarashafaei/Library/Developer/Xcode/DerivedData/test4-bwkmkpnssqhpxgfntgtgkmzrcskr/Build/Products/Debug/test4 normal x86_64
    cd /Users/sarashafaei/Desktop/test/test4
    setenv MACOSX_DEPLOYMENT_TARGET 10.7
    /Developer/usr/bin/g++-4.2 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.7.sdk -L/Users/sarashafaei/Library/Developer/Xcode/DerivedData/test4-bwkmkpnssqhpxgfntgtgkmzrcskr/Build/Products/Debug -L/usr/local/lib -L/usr/local/lib/ImageMagick -L/usr/local/lib/ImageMagick-6.7.2 -L/usr/local/lib/pkgconfig -L/usr/local/lib/ImageMagick/modules-Q16 -L/usr/local/lib/ImageMagick-6.7.2/modules-Q16 -L/usr/local/lib/ImageMagick/modules-Q16/coders -L/usr/local/lib/ImageMagick/modules-Q16/filters -L/usr/local/lib/ImageMagick-6.7.2/modules-Q16/coders -L/usr/local/lib/ImageMagick-6.7.2/modules-Q16/filters -F/Users/sarashafaei/Library/Developer/Xcode/DerivedData/test4-bwkmkpnssqhpxgfntgtgkmzrcskr/Build/Products/Debug -filelist /Users/sarashafaei/Library/Developer/Xcode/DerivedData/test4-bwkmkpnssqhpxgfntgtgkmzrcskr/Build/Intermediates/test4.build/Debug/test4.build/Objects-normal/x86_64/test4.LinkFileList -mmacosx-version-min=10.7 -o /Users/sarashafaei/Library/Developer/Xcode/DerivedData/test4-bwkmkpnssqhpxgfntgtgkmzrcskr/Build/Products/Debug/test4

Undefined symbols for architecture x86_64:
  "Magick::InitializeMagick(char const*)", referenced from:
      _main in main.o
  "Magick::Image::Image(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)", referenced from:
      _main in main.o
  "Magick::Image::~Image()", referenced from:
      _main in main.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

Any help would be appreciated.

回答1:

Even though you have a nice and long linker line, I can't find any missing -lImageMagick in there. You need to add this flag at the end of your linker/compiler invocation to actually link to the Magick library.