64位Linux編譯cximage手記

     CxImage類是一個優秀的圖像操作類庫。它可以快捷地存取、顯示、轉換各種圖像。相比於OpenIL,FreeImage,PaintLib等其他圖像處理庫,CxImage類庫是完全免費、開源的。另外這是一個典型的MFC風格C++類庫,估計最早就是在MFC上開發的吧,後續才移植到Linux上。


     最近項目需要,以前在Windows客戶端上用Cximage進行的圖片處理,要移植到Linux服務端,因此嘗試在Linux上編譯和使用Cximage。中間遇到不少問題,特記錄如下。

1、 下載Linux的cximage tar包
cximage 主頁


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



發佈了32 篇原創文章 · 獲贊 25 · 訪問量 23萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章