參考網上的教程安裝dlib
安裝教程1
sudo apt-get install libboost-python-dev cmake sudo pip install dlib
安裝教程2
ubuntu下的安裝
進入官網下載安裝包,解壓
安裝編譯所需工具 sudo apt-get install cmake
sudo apt-get install libboost-python-dev
進入dlib的目錄 sudo python setup.py install
出現下面的錯誤
$ python Python 2.7.12 (default, Nov 19 2016, 06:48:10) [GCC 5.4.0 20160609] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import dlib Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: ./dlib.so: undefined symbol: png_set_longjmp_fn >>>
問題原因
這個是在Linux上編譯項目的時候,一個動態庫層用到的一個函數實現未找到,,
系統安裝了libpng16.so.16.29.0*, readelf -s了下這個文件,是有png_set_longjmp_fn這個符號的
lrwxrwxrwx 1 root root 19 6月 1 10:49 libpng16.so -> libpng16.so.16.29.0* lrwxrwxrwx 1 root root 19 6月 1 10:49 libpng16.so.16 -> libpng16.so.16.29.0*
-rwxr-xr-x 1 root root 926416 6月 1 10:49 libpng16.so.16.29.0*
查找原因發現:
系統中還有一個位置安裝了舊版本的libpng12,
/lib/x86_64-linux-gnu
-rwxrwxrwx 1 root root 149800 10月 19 19:21 libpng12.so.0*
-rwxrwxrwx 1 root root 149800 10月 19 19:21 libpng12.so.0.54.0*
該版本中的libpng中是沒有png_set_longjmp_fn的函數定義的,編譯相關的庫 dlib 依賴的時候,
首先是鏈接到/lib/x86_64-linux-gnu/libpng12.so.0找不到該函數,報錯。
解決方法1:(推薦)
cd /lib/x86_64-linux-gnu
sudo rm libpng12.so.0 (這里刪除老版本的libpng庫)
sudo rm libpng12.so.0.54.0
sudo ln -s /usr/local/lib/libpng16.so.16 ./libpng16.so.16 (建立一個鏈接,指向libpng16)
這樣系統編譯的時候,鏈接到/usr/local/lib/libpng16.so.16的庫中
解決方法2:
png使用過程問題小結:
(1) libpng “png_set_longjmp_fn” not found
解決思路
In my case, I have the old png 1.2 came with my ubuntu installed in /usr. I installed the 1.6.x in /usr/local. In my make system, the default include /usr/include and linking /usr/lib were picked up. When compiling any software that rely on the new interface, you need to add
CPPFLAGS="-I/usr/local/include $CPPFLAGS"
LDFLAGS="-L/usr/local/lib $LDFLAGS"
this will pick up
grep png_set_longjmp_fn png.h
PNG_EXPORT(8, jmp_buf*, png_set_longjmp_fn, (png_structrp png_ptr,
(*png_set_longjmp_fn((png_ptr), longjmp, (sizeof (jmp_buf))))
翻譯過來就是:編譯程序時,在makefile 中 加入
CPPFLAGS="-I/usr/local/include $CPPFLAGS"
LDFLAGS="-L/usr/local/lib $LDFLAGS"
使得所依賴的libpng庫都指向自己安裝的最新libpng16