Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux綜合 >> 學習 Linux

CentOS 7 編譯安裝 Mapnik 與常見錯誤處理

本文使用 Mapnik 的 Master 版本,需注意 Master 需要 glibc 2.14 以上的支援。編譯過程中的疑難可參考官方 InstallationTroubleshooting 章節。

git clone https://github.com/mapnik/mapnik.git

安裝相依套件

yum install boost-devel postgresql-devel proj-devel proj-epsg

擴充功能所需:

yum install sqlite-devel libpng-devel libtiff-devel libjpeg-devel libicu-devel

記憶體不足的因應

官方建議編譯時至少要有 5GB 記憶體(供 g++ 使用)。記憶體較小的機器可能會異常退出並出現:

g++: internal compiler error: Killed (program cc1plus)

可以暫時增加磁碟交換空間來解決:

sudo dd if=/dev/zero of=/swapfile bs=64M count=16
sudo mkswap /swapfile
sudo swapon /swapfile

編譯完成後再還原:

sudo swapoff /swapfile
sudo rm /swapfile

開始編譯

./configure
make
make install

過程中可能出現如下錯誤:

CentOS 7 編譯安裝 Mapnik 與常見錯誤處理

Harfbuzz not found

若看到下列訊息,代表缺少 HarfBuzz 文字塑形函式庫:

Checking for C++ library harfbuzz... no
Could not find required header or shared library for harfbuzz
Exiting... the following required dependencies were not found:
- harfbuzz (HarfBuzz text shaping library | configure with HB_LIBS & HB_INCLUDES)

解法是明確指定 HB_LIBS 與 HB_INCLUDES。要注意兩者都是「目錄」而非 cflags/ldflags,且 HB_INCLUDES 不需要再包含 harfbuzz 子目錄本身。

若 pkg-config 輸出:

$ pkg-config --libs --cflags harfbuzz
-I/usr/local/Cellar/harfbuzz/0.9.35_1/include/harfbuzz -L/usr/local/Cellar/harfbuzz/0.9.35_1/lib -lharfbuzz

實際上你需要的是:

$ ./configure HB_LIBS=/usr/local/Cellar/harfbuzz/0.9.35_1/lib \
              HB_INCLUDES=/usr/local/Cellar/harfbuzz/0.9.35_1/include

簡單測試

python -c "import mapnik"

若出現:

ImportError: libmapnik.so.3.0: cannot open shared object file: No such file or directory

需手動補上 so 的位置:

vim /etc/ld.so.conf.d/mapnik-x86_64.conf
# 新增一行:/usr/local/lib
ldconfig

沒問題的話可以跑渲染範例,會產生不同品質與格式的圖片:

python demo/python/rundemo.py
Copyright © Linux教程網 All Rights Reserved