我想在Centos 6.3 x86_64上编译pHash 0.9.5这里是我所遵循的步骤的细节:
$ yum install unzip $ wget https://downloads.sourceforge.net/project/cimg/CImg-1.5.4.zip $ unzip CImg-1.5.4.zip $ $ wget http://phash.org/releases/pHash-0.9.5.tar.gz $ tar xvf pHash-0.9.5.tar.gz $ $ cp CImg-1.5.4/CImg.h pHash-0.9.5/src/ $ $ cd pHash-0.9.5 $ ./configure --enable-video-hash=no --enable-audio-hash=no $ make $ make install
然后一旦安装了pHash,我试着安装这样的PHP扩展:
$ cd bindings/php $ phpize $ ./configure checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking for a sed that does not truncate output... /bin/sed checking for cc... cc checking for C compiler default output file name... a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether cc accepts -g... yes checking for cc option to accept ISO C89... none needed checking how to run the C preprocessor... cc -E checking for icc... no checking for suncc... no checking whether cc understands -c and -o together... yes checking for system library directory... lib checking if compiler supports -R... no checking if compiler supports -Wl,-rpath,... yes checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking target system type... x86_64-unknown-linux-gnu checking for PHP prefix... /usr checking for PHP includes... -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib checking for PHP extension directory... /usr/lib64/php/modules checking for PHP installed headers prefix... /usr/include/php checking if debug is enabled... no checking if zts is enabled... no checking for re2c... no configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers. checking for gawk... gawk checking whether pHash is available... yes, shared checking for g++... g++ checking whether we are using the GNU C++ compiler... yes checking whether g++ accepts -g... yes checking how to run the C++ preprocessor... g++ -E checking for pHash in default path... found in /usr/local checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking pHash.h usability... no checking pHash.h presence... no checking for pHash.h... no configure: error: 'pHash.h' header not found $
所以显然pHash已经安装正确checking for pHash in default path... found in /usr/local但没有findpHash.h 。
pHash.h位于/usr/local/include 。 我试图debuggingconfiguration脚本,看看这个文件是不是位于,但现在我不是真的成功。
如果有人有一个想法,我会很感激。 谢谢。
马克西姆
更新:
显然根据config.log :它是由CImg.h库引起的,所以我想知道如果我要注册某个地方这个头文件…
configure:5136: checking pHash.h usability configure:5153: g++ -c -g -O2 -I/usr/include/php -I/usr/include/php/main -I/usr/include/php/TSRM -I/usr/include/php/Zend -I/usr/include/php/ext -I/usr/include/php/ext/date/lib -I/usr/local/include -DHAVE_PHASH conftest.cpp >&5 In file included from conftest.cpp:51: /usr/local/include/pHash.h:50:18: error: CImg.h: No such file or directory In file included from conftest.cpp:51: /usr/local/include/pHash.h:51: error: 'cimg_library' is not a namespace-name /usr/local/include/pHash.h:51: error: expected namespace-name before ';' token In file included from conftest.cpp:51: /usr/local/include/pHash.h:144: error: expected ';' before '<' token /usr/local/include/pHash.h:211: error: expected ',' or '...' before '<' token /usr/local/include/pHash.h:250: error: expected ',' or '...' before '<' token /usr/local/include/pHash.h:273: error: expected ',' or '...' before '<' token In file included from conftest.cpp:51: /usr/local/include/pHash.h:292: error: expected initializer before '<' token
UPDATE2:
好的,所以我运行了cpp -Wp,-v来查看预编译器加载了哪些默认path:
$ cpp -Wp,-v ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.4.7/include-fixed" ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../x86_64-redhat-linux/include" #include "..." search starts here: #include <...> search starts here: /usr/local/include /usr/lib/gcc/x86_64-redhat-linux/4.4.7/include /usr/include End of search list.
所以/usr/local/include是默认path的一部分,所以我已经在这个文件夹中复制了CImg.h并且尝试再次运行./configure 。 现在我有一个audiophash.h显然是一个已知问题的问题。
我会尝试修复它,并回到这里,希望能回答我的问题。
好的,这里是完整的答案:
下载所需的库
$ cd ~/download $ yum install libsndfile-devel unzip $ wget https://downloads.sourceforge.net/project/cimg/CImg-1.5.4.zip $ wget http://phash.org/releases/pHash-0.9.5.tar.gz $ wget http://www.mega-nerd.com/SRC/libsamplerate-0.1.8.tar.gz $ wget http://sourceforge.net/projects/mpg123/files/mpg123/1.15.1/mpg123-1.15.1.tar.bz2/download
编译pHash所需的库。 由于PHP扩展,我们需要启用audio和图像支持。
$ tar xvf libsamplerate-0.1.8.tar.gz $ cd libsamplerate-0.1.8 $ ./configure $ make && make install $ $ tar xvf mpg123-1.15.1 $ cd mpg123-1.15.1 $ ./configure $ make && make install We need to copy CImg.h in the /user/local/include folder $ unzip CImg-1.5.4.zip $ cp CImg-1.5.4/CImg.h /usr/local/include
编译pHash库
$ tar xvf pHash-0.9.5.tar.gz $ cd pHash-0.9.5 $ ./configure --enable-video-hash=no $ make && make install Compile the PHP extension $ cd bindings/php $ phpize $ ./configure LIBS="-lpthread"
编辑pHash.cpp
我不得不编辑pHash.cpp来修复编译错误。 我想你只需要做,如果你使用php> = 5.3
$ vi /root/download/pHash-0.9.5/bindings/php/pHash.cpp # line 106, replace "function_entry" by "zend_function_entry" # save and close Finish the compilation $ make $ make test $ make install # finally enable pHash in the php.ini adding extension=pHash.so # restart apache
可选 – 如果要将散列存储在数据库(SQL)中:
你需要编辑pHash.cpp来修改散列的返回值。
默认情况下, ph_dct_imagehash($file)返回一个*ulong64 (指针),我们需要检索一个string以将其存储在数据库中。
请参阅: https : //github.com/lucidix/phash/commit/5be2d454c932152e9b2395e21f97a008c6bd8766
我知道这是有点题外话,但我努力在Ubuntu 12.04 LTS amd64上安装pHash + php扩展,所以我也分享了我的安装日志:
$ sudo apt-get install make libsndfile-dev checkinstall $ sudo apt-get install cimg-dev libjpeg62 libfftw3-3 imagemagick graphicsmagick $ wget http://downloads.sourceforge.net/project/libpng/libpng15/1.5.18/libpng-1.5.18.tar.gz $ tar xvf libpng-1.5.18.tar.gz $ cd libpng-1.5.18 $ ./configure $ make check $ make install
cimg有很多依赖关系,如果你需要处理比位图以外的其他格式(假设你不想自己处理转换),那么它是必需的。
libjpeg62 =>支持jpeg
libpng15 => png支持
libfftw3-3 =>傅里叶变换
imagemagick =>进行格式转换
graphicsmagick => imagemagick fork,必需
$ sudo apt-get install libsamplerate0-dev libmpg123-dev
audio散列需要这两个库。 PHP绑定目前要求pHash库有audio哈希能够编译(见http://lists.phash.org/htdig.cgi/phash-support-phash.org/2012-December/000139.html )
$ cd $ wget http://phash.org/releases/pHash-0.9.6.tar.gz $ tar xvf pHash-0.9.6.tar.gz $ cd pHash-0.9.6 $ ./configure --enable-openmp=yes --enable-video-hash=no LIBS='-lpthread' $ make $ sudo checkinstall --pkgname=phash --pkgversion="1:$(date +%Y%m%d%H%M)-0.9.6" --backup=no \ --deldoc=yes --fstrans=no --default
我使用checkinstall来创build和pipe理一个phash包,但是你可以去make install来代替。 LIBS =' – lpthread'告诉configure脚本使用lpthread库(否则它不会在我的机器上编译)
使用我的PHP版本(5.3)进行编译时,发布的php绑定将不起作用,因为API版本问题不明显,所以我使用了这个源代码:
$ cd $ git clone --depth=1 http://github.com/Alexis2004/php-phash $ cd php-phash $ pear install CodeGen_PECL $ ./compile.sh $ make test $ make install
你现在要做的就是把'extension = pHash.so'添加到你的php.ini文件中,而且你很好!
@ maxwell2022的实现并没有涵盖libpng和ffmpeg。 没有这些依赖关系,PHP绑定不适合我。
这里是我的安装日志:
yum install libsndfile-devel -y cd wget http://www.mega-nerd.com/SRC/libsamplerate-0.1.8.tar.gz tar xvf libsamplerate-0.1.8.tar.gz cd libsamplerate-0.1.8 ./configure make && make install cd wget http://sourceforge.net/projects/mpg123/files/mpg123/1.15.4/mpg123-1.15.4.tar.bz2/download tar xvf mpg123-1.15.4.tar.bz2 cd mpg123-1.15.4 ./configure make && make install cd wget http://sourceforge.net/projects/libpng/files/libpng15/1.5.17/libpng-1.5.17.tar.gz/download tar xvf libpng-1.5.17.tar.gz cd libpng-1.5.17 ./configure make && make install cd wget https://downloads.sourceforge.net/project/cimg/CImg-1.5.6.zip unzip CImg-1.5.6.zip cp CImg-1.5.6/CImg.h /usr/local/include su -c 'yum localinstall --nogpgcheck http://download1.rpmfusion.org/free/el/updates/6/i386/rpmfusion-free-release-6-1.noarch.rpm http://download1.rpmfusion.org/nonfree/el/updates/6/i386/rpmfusion-nonfree-release-6-1.noarch.rpm' yum install ffmpeg ffmpeg-devel libpng-devel -y ln -s /usr/include/ffmpeg/libavutil /usr/include/libavutil ln -s /usr/include/ffmpeg/libavformat /usr/include/libavformat ln -s /usr/include/ffmpeg/libavcodec /usr/include/libavcodec ln -s /usr/include/ffmpeg/libswscale /usr/include/libswscale cd wget http://phash.org/releases/pHash-0.9.6.tar.gz tar xvf pHash-0.9.6.tar.gz cd pHash-0.9.6 ./configure make && make install cd bindings/php phpize ./configure make make install echo 'extension=pHash.so' > /etc/php.d/phash.ini
而且,你需要重新开始……快速清理。
cd ~/libsamplerate-0.1.8 && make uninstall cd && rm -fr libsamplerat* cd ~/mpg123-1.15.4 && make uninstall cd && rm -fr mpg123-1.15.* cd ~/libpng-1.5.17 && make uninstall cd && rm -fr libpng-1.5.* cd ~/pHash-0.9.6 && make uninstall cd && rm -fr pHash* rm -fr ~/CImg-1.5.6 rm -f CImg* rm -f /usr/local/include/CImg.h