您的位置:首页 > 运维架构 > Linux

64位Linux编译cximage手记

2015-10-22 22:20 751 查看
     CxImage类是一个优秀的图像操作类库。它可以快捷地存取、显示、转换各种图像。相比于OpenIL,FreeImage,PaintLib等其他图像处理库,CxImage类库是完全免费、开源的。另外这是一个典型的MFC风格C++类库,估计最早就是在MFC上开发的吧,后续才移植到Linux上。

     最近项目需要,以前在Windows客户端上用Cximage进行的图片处理,要移植到Linux服务端,因此尝试在Linux上编译和使用Cximage。中间遇到不少问题,特记录如下。

1、 下载Linux的cximage tar包

cximage 主页
http://www.xdp.it/cximage.htm

Linux 包下载地址
http://www.xdp.it/cgi-bin/dl.pl?cximage/cximage599c_tar

2、下载后得到cximage599c_tar.zip,然后将其解压

unzip cximage599c_tar.zip
tar xzvf cximage599c.tar.gz
cd cximage599c/


3、 ./configure; make
其中make时报错:
cd . && /home/zhl/cximage599c/admin/missing aclocal-1.4
WARNING: `aclocal-1.4' is needed, and you do not seem to have it handy on your
system.  You might have modified some files without having the
proper tools for further handling them.  Check the `README' file,
it often tells you about the needed prerequirements for installing
this package.  You may also peek at any GNU archive site, in case
some other package would contain this missing `aclocal-1.4' program.
make: *** [aclocal.m4] Error 1


系统有安装高版本的automake,难道一定要切换到低版本? 

rpm -aq | grep automake
automake-1.13.4-3.el7.noarch


尝试手动修改Makefile里面aclocal的版本号,仍然有问题。最后发现重新生成 aclocal.m4和Makefile就可以了:

解决步骤如下:
#重新生成 aclocal.m4
aclocal
#重新生成configure文件
autoconf -i -v -f
# 删除原来的makefile
find ./ -name Makefile -exec rm -rf {} \;
# 重新生成Makefile
./configure


4、解决后重新make,编译报其他错:
mv -f .deps/ximajbg.Tpo .deps/ximajbg.Po
g++ -DHAVE_CONFIG_H -I. -I../..       -MT ximajas.o -MD -MP -MF .deps/ximajas.Tpo -c -o ximajas.o ximajas.cpp
In file included from ximajas.h:19:0,
from ximajas.cpp:8:
../jasper/include/jasper/jasper.h:114:31: fatal error: jasper/jas_config.h: No such file or directory
#include <jasper/jas_config.h>

估计是头文件路径设置的不完整,重新configure,添加头文件路径:
# 删除原来的 Makefile
find ./ -name Makefile -exec rm -rf {}  \;
# 添加--with-extra-includes指定头文件路径,重新生成Makefile
./configure --with-extra-includes=/home/cximage599c/cximage/jasper/include/

之后可以在 cximage/jasper/Makefile 中看到添加的 include 路径。


5、 再次make clean;make  ,还有错误.

mv -f .deps/ximabmp.Tpo .deps/ximabmp.Po
g++ -DHAVE_CONFIG_H -I. -I../.. -I/home/cximage599c/cximage/jasper/include/      -MT tif_xfile.o -MD -MP -MF .deps/tif_xfile.Tpo -c -o tif_xfile.o tif_xfile.cpp
tif_xfile.cpp: In function ‘TIFF* _TIFFOpenEx(CxFile*, const char*)’:
tif_xfile.cpp:102: error: cast from ‘CxFile*’ to ‘int’ loses precision
make[3]: *** [tif_xfile.o] Error 1

解决方法:
修改代码 ./cximage/CxImage/tif_xfile.cpp
extern"C" TIFF* _TIFFOpenEx(CxFile* stream, constchar* mode)
{
      //return (_TIFFFdOpen((int)stream, "TIFF IMAGE", mode));// 64bits 系统,int 改成long
      return (_TIFFFdOpen((long)stream, "TIFF IMAGE", mode)); 
}

6、 最后cximage编译通过,但编译自己的程序,链接cximage相关的静态库时又提示需要-fPIC选项.
/usr/bin/ld: /home/xxxxx/libCxImage.a(ximatran.o): relocation R_X86_64_32S against `.rodata' can not be used when making a shared object; recompile with -fPIC
/home/<span style="font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace; widows: auto;">xxxxx</span><span style="widows: auto; font-family: Monaco, Consolas, Courier, 'Lucida Console', monospace;">/libCxImage.a: could not read symbols: Bad value</span>


因此删除Makefile后,添加CPPFLAGS="=-fPIC" 选项,重新执行configure生成Makefile

CPPFLAGS="=-fPIC"  ./configure --with-extra-includes=/home/cximage599c/cximage/jasper/include/

编译步骤总结:
1、 修改 ./cximage/CxImage/tif_xfile.cpp 代码
2、 aclocal
3、 autoconf -i -v -f
4、 automake --add-mising
5、 find ./ -name Makefile -exec rm -rf {} \;
6、 CPPFLAGS="=-fPIC"   ./configure --with-extra-includes=/home/cximage599c/cximage/jasper/include/
CPPFLAGS 根据实际需要添加。
7、 make; make install



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: