mac下安装php zookeeper扩展
安装步骤
php-zookeeper依赖libzookeeper,所以需要先安装libzookeeper
安装libzookeeper
cd /usr/local/src/
wget http://mirror.bit.edu.cn/apache/zookeeper/stable/zookeeper-3.4.12.tar.gz
tar -xf zookeeper-3.4.12.tar.gz
cd zookeeper-3.4.12/src/c
./configure -prefix=/usr/local/zookeeper/zookeeper-3.4.12/
make && make install
安装php zookeeper扩展
cd /usr/local/src/
wget https://pecl.php.net/get/zookeeper-0.5.0.tgz
tar zxvf zookeeper-0.5.0.tgz
cd zookeeper-0.5.0
phpize
./configure –with-php-config=/usr/local/php/bin/php-config –with-libzookeeper-dir=/usr/local/zookeeper/zookeeper-3.4.12/
make && make install
修改php.ini,新增extension=zookeeper.so,然后重启php
vim /usr/local/etc/php/7.0/php.ini
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
extension_dir = "/usr/local/lib/php/pecl/20151012"
; On windows:
; extension_dir = "ext"
extension=zookeeper.so
遇到的问题
无论是安装libzookeeper还是安装php zookeeper扩展,在执行make && make install命令时会出现类似下面错误。网上查找了很大资料,都没这方面的解决方案,貌似只有在mac下才会有这样的问题。
/Library/Developer/CommandLineTools/usr/bin/make all-am
/bin/sh ./libtool --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I./include -I./tests -I./generated -Wall -Werror -g -O2 -D_GNU_SOURCE -MT zookeeper.lo -MD -MP -MF .deps/zookeeper.Tpo -c -o zookeeper.lo `test -f 'src/zookeeper.c' || echo './'`src/zookeeper.c
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I./include -I./tests -I./generated -Wall -Werror -g -O2 -D_GNU_SOURCE -MT zookeeper.lo -MD -MP -MF .deps/zookeeper.Tpo -c src/zookeeper.c -fno-common -DPIC -o .libs/zookeeper.o
In file included from src/zookeeper.c:37:
/usr/local/include/string.h:49:1: error: unknown type name 'HASHKIT_API'
HASHKIT_API
^
/usr/local/include/string.h:50:1: error: expected identifier or '('
void hashkit_string_free(hashkit_string_st *ptr);
^
/usr/local/include/string.h:53:1: error: unknown type name 'HASHKIT_API'
HASHKIT_API
^
/usr/local/include/string.h:54:7: error: expected ';' after top level declarator
size_t hashkit_string_length(const hashkit_string_st *self);
^
/usr/local/include/string.h:56:1: error: unknown type name 'HASHKIT_API'
HASHKIT_API
^
/usr/local/include/string.h:57:1: error: expected identifier or '('
const char *hashkit_string_c_str(const hashkit_string_st* self);
^
src/zookeeper.c:505:19: error: implicitly declaring library function 'strdup' with type 'char *(const char *)'
[-Werror,-Wimplicit-function-declaration]
char *hosts = strdup(zh->hostname);
^
src/zookeeper.c:505:19: note: include the header <string.h> or explicitly provide a declaration for 'strdup'
src/zookeeper.c:524:10: error: implicit declaration of function 'strtok_r' is invalid in C99
[-Werror,-Wimplicit-function-declaration]
host=strtok_r(hosts, ",", &strtok_last);
^
src/zookeeper.c:524:9: error: incompatible integer to pointer conversion assigning to 'char *' from 'int'
[-Werror,-Wint-conversion]
host=strtok_r(hosts, ",", &strtok_last);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/zookeeper.c:526:27: error: implicitly declaring library function 'strrchr' with type
'char *(const char *, int)' [-Werror,-Wimplicit-function-declaration]
char *port_spec = strrchr(host, ':');
^
src/zookeeper.c:526:27: note: include the header <string.h> or explicitly provide a declaration for 'strrchr'
src/zookeeper.c:604:9: error: implicitly declaring library function 'memset' with type
'void *(void *, int, unsigned long)' [-Werror,-Wimplicit-function-declaration]
memset(&hints, 0, sizeof(hints));
^
src/zookeeper.c:604:9: note: include the header <string.h> or explicitly provide a declaration for 'memset'
src/zookeeper.c:640:49: error: implicitly declaring library function 'strerror' with type 'char *(int)'
[-Werror,-Wimplicit-function-declaration]
LOG_ERROR(("getaddrinfo: %s\n", strerror(errno)));
^
src/zookeeper.c:640:49: note: include the header <string.h> or explicitly provide a declaration for 'strerror'
src/zookeeper.c:669:17: error: implicitly declaring library function 'memcpy' with type 'void *(void *, const
void *, unsigned long)' [-Werror,-Wimplicit-function-declaration]
memcpy(addr, res->ai_addr, res->ai_addrlen);
^
src/zookeeper.c:669:17: note: include the header <string.h> or explicitly provide a declaration for 'memcpy'
src/zookeeper.c:681:14: error: incompatible integer to pointer conversion assigning to 'char *' from 'int'
[-Werror,-Wint-conversion]
host = strtok_r(0, ",", &strtok_last);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/zookeeper.c:849:20: error: implicitly declaring library function 'strchr' with type
'char *(const char *, int)' [-Werror,-Wimplicit-function-declaration]
index_chroot = strchr(host, '/');
^
src/zookeeper.c:849:20: note: include the header <string.h> or explicitly provide a declaration for 'strchr'
src/zookeeper.c:856:13: error: implicitly declaring library function 'strlen' with type
'unsigned long (const char *)' [-Werror,-Wimplicit-function-declaration]
if (strlen(zh->chroot) == 1) {
^
src/zookeeper.c:856:13: note: include the header <string.h> or explicitly provide a declaration for 'strlen'
src/zookeeper.c:862:24: error: implicitly declaring library function 'strncpy' with type 'char *(char *, const
char *, unsigned long)' [-Werror,-Wimplicit-function-declaration]
zh->hostname = strncpy(zh->hostname, host, (index_chroot - host));
^
src/zookeeper.c:862:24: note: include the header <string.h> or explicitly provide a declaration for 'strncpy'
src/zookeeper.c:932:5: error: implicitly declaring library function 'strcpy' with type
'char *(char *, const char *)' [-Werror,-Wimplicit-function-declaration]
strcpy(ret_str, zh->chroot);
^
src/zookeeper.c:932:5: note: include the header <string.h> or explicitly provide a declaration for 'strcpy'
src/zookeeper.c:933:12: error: implicitly declaring library function 'strcat' with type
'char *(char *, const char *)' [-Werror,-Wimplicit-function-declaration]
return strcat(ret_str, client_path);
^
src/zookeeper.c:933:12: note: include the header <string.h> or explicitly provide a declaration for 'strcat'
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make[1]: *** [zookeeper.lo] Error 1
make: *** [all] Error 2
解决方法
分析上面问题,基本是变量和一些string函数没有被显示声明。解决方法就是将没有定义的变量注释掉,将没有显示声明的函数补上。
重写/usr/local/include/string.h 文件如下,可以直接拷贝使用。然后重新执行make && make install,就可以了。
/* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
*
* HashKit library
*
* Copyright (C) 2011-2012 Data Differential, http://datadifferential.com/
* Copyright (C) 2009-2010 Brian Aker All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
*
* * The names of its contributors may not be used to endorse or
* promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#pragma once
#ifdef __cplusplus
struct hashkit_string_st;
#endif
#ifdef __cplusplus
extern "C" {
#endif
/*
HASHKIT_API
void hashkit_string_free(hashkit_string_st *ptr);
HASHKIT_API
size_t hashkit_string_length(const hashkit_string_st *self);
HASHKIT_API
const char *hashkit_string_c_str(const hashkit_string_st* self);
*/
char *strdup(const char *s);
char *strtok_r(char *s, const char *delim, char **ptrptr);
char *strrchr(const char *, int);
void *memset(void *, int, unsigned long);
char *strerror(int);
void *memcpy(void *, const void *, unsigned long);
char *strchr(const char *, int);
unsigned long strlen(const char *);
char *strncpy(char *, const char *, unsigned long);
char *strcpy(char *, const char *);
char *strcat(char *, const char *);
int strncmp(const char *, const char *, unsigned long);
int strcmp(const char *, const char *);
void *memmove(void *, const void *, unsigned long);
int memcmp(const void *, const void *, unsigned long);
void *memchr(const void *, int, unsigned long);
#ifdef __cplusplus
} // extern "C"
#endif