c-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
我还需要其他链接才能成功链接它吗?我链接正确吗?提前致谢.
解决方法:
尝试反转Magick库,添加MagickWand库(并在最后放置libz和其他基本图像库,以及动态链接器库):
... -lpthread -lMagick++ -lMagickWand -lMagickCore -lz -ldl
有关为何静态库顺序很重要的信息,请参见Linker Order – GCC.
标签:magick,c,linux,imagemagick,cross-compiling 来源: https://codeday.me/bug/20191011/1890250.html