最近項目需要,以前在Windows客戶端上用Cximage進行的圖片處理,要移植到Linux服務端,因此嘗試在Linux上編譯和使用Cximage。中間遇到不少問題,特記錄如下。
2、下載後得到cximage599c_tar.zip,然後將其解壓
unzip cximage599c_tar.zip
tar xzvf cximage599c.tar.gz
cd cximage599c/
3、 ./configure; 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
rpm -aq | grep automake
automake-1.13.4-3.el7.noarch
#重新生成 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>
# 刪除原來的 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