Magick ++链接错误

时间:2011-09-07 07:09:05

标签: c++ linux imagemagick cross-compiling magick++

我这里有一个使用Magick ++(ImageMagick接口)库的简单图像转换器代码。(Eclipse IDE)

#include <Magick++.h>
#include <string>
#include <iostream>

using namespace std;

using namespace Magick;

int main(int argc,char **argv) 
{ 
    Image image; 
    image.read("/home/usr1/test.tiff");
    image.write( "/home/usr1/test.bmp" ); 
    return 0;
}

我正在使用arm-linux目标进行交叉编译。代码编译成功,但在链接部分,我得到了未定义的引用错误。

/usr/local/lib/libMagick++/libMagickCore.a(dlopen.o)(.text+0x144): In function `vm_open':
ltdl/loaders/dlopen.c:194: undefined reference to `dlopen'
/usr/local/lib/libMagick++/libMagickCore.a(dlopen.o)(.text+0x158):ltdl/loaders/dlopen.c:198: undefined reference to `dlerror'
/usr/local/lib/libMagick++/libMagickCore.a(dlopen.o)(.text+0x16c): In function `vm_close':
ltdl/loaders/dlopen.c:212: undefined reference to `dlclose'
/usr/local/lib/libMagick++/libMagickCore.a(dlopen.o)(.text+0x17c):ltdl/loaders/dlopen.c:214: undefined reference to `dlerror'
/usr/local/lib/libMagick++/libMagickCore.a(dlopen.o)(.text+0x198): In function `vm_sym':
ltdl/loaders/dlopen.c:227: undefined reference to `dlsym'
/usr/local/lib/libMagick++/libMagickCore.a(dlopen.o)(.text+0x1ac):ltdl/loaders/dlopen.c:231: undefined reference to `dlerror'

我使用以下命令编译代码:

/opt/Mx800SDK/vfitc/cross/bin/arm-linux-g++ -DMx870 -I/opt/Mx800SDK/vfitc/cross/arm-linux/include -I/usr/local/include/ImageMagick -I/opt/Mx800SDK/include -O2 -Wall -c -fmessage-length=0 -fno-strict-aliasing -o'main.o' '../main.cpp'

并链接:

/opt/Mx800SDK/vfitc/cross/bin/arm-linux-g++ -L/opt/Mx800SDK/lib -L/usr/local/lib/libMagick++ -o'imgConverter' ./main.o -lpthread -lMagick++ -lMagickWand -lMagickCore -ltiff -lz

我需要成功链接它的其他库吗?我连接它吗?提前谢谢。

1 个答案:

答案 0 :(得分:5)

尝试反转Magick库,添加MagickWand库(最后放置libz和其他基本图像库,以及动态链接库):

... -lpthread -lMagick++ -lMagickWand -lMagickCore -lz -ldl

请参阅Linker Order - GCC了解静态库的顺序为何如此重要。