1. 程式人生 > >linux上安裝libpng庫以及zlib庫

linux上安裝libpng庫以及zlib庫

hello ,大家好,我是jordy,一隻空著的杯子;歡迎各位朋友光臨我的部落格,多多溝通 ,我的QQ :   1760282809   

363232564

(一)下載libpng的庫:

我下載的是libpng-1.5.8 的安裝包

libpng-1.5.8.tar.xz 的包

注意xz是壓縮率超高的壓縮形式,相當於在tar的基礎上再壓縮一遍;

對於xz的包,應該先用命令xz –d libpng-1.5.8.tar.xz 解壓為 libpng-1.5.8.tar 包

在此基礎上再用tar xvf libpng-1.5.8.tar 命令解壓為libpng-1.5.8目錄;

如果麼有xz命令的話,則yum –y install 先安裝xz工具;

解壓後cd進入libpng-1.5.8 目錄

(二)安裝(三步):

./configure

./make

./make install

安裝完畢後顯示下述提示資訊:

make[2]: Leaving directory`/root/libpng-1.5.8'

test -z"/usr/local/share/man/man3" || /bin/mkdir -p"/usr/local/share/man/man3"

 /usr/bin/install -c -m 644 libpng.3 libpngpf.3'/usr/local/share/man/man3'

test -z"/usr/local/share/man/man5" || /bin/mkdir -p"/usr/local/share/man/man5"

 /usr/bin/install -c -m 644 png.5'/usr/local/share/man/man5'

test -z"/usr/local/include/libpng15" || /bin/mkdir -p "/usr/local/include/libpn                                                                                                                                                            g15"

 /usr/bin/install -c -m 644 pnglibconf.h'/usr/local/include/libpng15'

test -z "/usr/local/lib/pkgconfig"|| /bin/mkdir -p "/usr/local/lib/pkgconfig"

 /usr/bin/install -c -m 644 libpng15.pc'/usr/local/lib/pkgconfig'

test -z"/usr/local/include/libpng15" || /bin/mkdir -p"/usr/local/include/libpn                                                                                                                                                            g15"

 /usr/bin/install -c -m 644 png.h pngconf.h'/usr/local/include/libpng15'

make install-data-hook

make[2]: Entering directory`/root/libpng-1.5.8'

cd /usr/local/include; rm -f png.hpngconf.h pnglibconf.h

cd /usr/local/include; ln -s libpng15/png.hpng.h

cd /usr/local/include; ln -slibpng15/pngconf.h \

                pngconf.h

cd /usr/local/include; ln -slibpng15/pnglibconf.h \

                pnglibconf.h

cd /usr/local/lib/pkgconfig; rm -flibpng.pc

cd/usr/local/lib/pkgconfig; ln -s libpng15.pc libpng.pc

make[2]: Leaving directory`/root/libpng-1.5.8'

make[1]: Leaving directory`/root/libpng-1.5.8'

[[email protected] libpng-1.5.8]#

看到安裝後自動把編譯時需要的libpng15.pc檔案儲存在/usr/local/lib/pkgconfig目錄下了;

直接執行:

pkg-config libpng15  --libs –cflags 會報錯:顯然是沒有找到.pc檔案

[[email protected] libpng-1.5.8]# pkg-config libpng15  --libs --cflags

Package libpng15 was not found in thepkg-config search path.

Perhaps you should add the directorycontaining `libpng15.pc'

to the PKG_CONFIG_PATH environment variable

No package 'libpng15' found

需要需要配置PKG_CONFIG_PATH環境變數:

exportPKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH

配置完畢後再次執行:

pkg-config libpng15  --libs –cflags

顯示了libpng庫的標頭檔案和庫檔案的路徑:

-I/usr/local/include/libpng15  -L/usr/local/lib -lpng15

至此,libpng已經成功安裝並配置好,在編譯c或cpp檔案時,只需要加上pkg-config libpng15 --libs –cflags 即可成功連線libpng庫;

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

下面我們來安裝zlib庫

我這裡安裝的是zlib-1.2.8版本:

解壓;

tar zxvf zlib-1.2.8.tar.gz

然後進入目錄zlib-1.2.8:

然後三步安裝:

./configure

make

make install

安裝成功後會看到以下提示資訊:

[[email protected] zlib-1.2.8]# make install

cp libz.a /usr/local/lib

chmod 644 /usr/local/lib/libz.a

cp libz.so.1.2.8 /usr/local/lib

chmod 755 /usr/local/lib/libz.so.1.2.8

cp zlib.3 /usr/local/share/man/man3

chmod 644 /usr/local/share/man/man3/zlib.3

cp zlib.pc /usr/local/lib/pkgconfig

chmod644 /usr/local/lib/pkgconfig/zlib.pc

cp zlib.h zconf.h /usr/local/include

chmod 644 /usr/local/include/zlib.h/usr/local/include/zconf.h

看到zlib.pc位於/usr/local/lib/pkgconfig 目錄下:

則我們執行pkg-config zlib --libs --cflags測試標頭檔案和庫檔案的路徑:

[[email protected] zlib-1.2.8]# pkg-configzlib --libs --cflags

-I/usr/local/include  -L/usr/local/lib –lz

成功得到路徑:

和剛才安裝的libpng一起執行 看看路徑結果:

pkg-configlibpng15 zlib --libs --cflags

成功得到:

[[email protected] zlib-1.2.8]# pkg-configlibpng15 zlib --libs --cflags

-I/usr/local/include/libpng15-I/usr/local/include  -L/usr/local/lib-lpng15 –lz

至此,libpng以及zlib庫以及完整安裝完畢:

於是 我們呼叫一下命令,編譯一下.cpp原始檔,目的值為了生存可執行的Image檔案:

g++ -o Image Image.cpp -I `pkg-config libpng15 zlib --libs --cflags`

【大家可搜尋並關注我的微信公眾號,名稱:jordy的世界
後續會有持續更新,更多精彩等著您!】