PHP扩展加载错误
2016-03-02 15:23
746 查看
在php.ini中加入编译好的c++扩展(使用了protobuf)后,重启php-fpm报错如下:[root@iZ23eld3eqzZ baichuan]# service php-fpm restart Gracefully shutting down php-fpm . doneStarting php-fpm [libprotobuf ERROR google/protobuf/descriptor_database.cc:109] Symbol name "BidRequest" conflicts with the existing symbol "BidRequest".[libprotobuf FATAL google/protobuf/descriptor.cc:954] CHECK failed: generated_database_->Add(encoded_file_descriptor, size): terminate called after throwing an instance of 'google::protobuf::FatalException' what(): CHECK failed: generated_database_->Add(encoded_file_descriptor, size): /etc/init.d/php-fpm: line 50: 21303 Aborted $php_fpm_BIN --daemonize $php_opts failed在Linux上编译google protobuff时,configure 默认选项是生成动态库,即libprotobuf.so文件。如果同时在多个动态库(动态库以dlopen方式动态加载)中使用同一buff结构,则运行时会报错误:
ibprotobuf ERROR google/protobuf/descriptor_database.cc:57] File already exists in database: foo/foo.proto libprotobuf FATAL google/protobuf/descriptor.cc:862] CHECK failed: generated_database_->Add(encoded_file_descriptor, size): terminate called after throwing an instance of 'google::protobuf::FatalException' what(): CHECK failed: generated_database_->Add(encoded_file_descriptor, size):为了解决这个问题,google protobuff,则不能以动态库的形式调用,改用静态库的形式在编译时加载。编译google protobuff时,在configure 时加上选项:
configrue --disable-shared
即可编译成静态库:libprotobuf.a 但是默认的configure文件中,在编译时未加-fPIC ,导致在引用静态库的工程中编译链接时报错误:
libs/assert.o: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC .libs/assert.o: could not read symbols: Bad value
解决该问题,需要重新编译google protobuff库,并添加编译选项:-fPIC
以文本形式打开google buff代码目录下的configure文件,在把第2575至2578行修改为如下:
if test "x${ac_cv_env_CFLAGS_set}" = "x"; then : CFLAGS="-fPIC" fi if test "x${ac_cv_env_CXXFLAGS_set}" = "x"; then : CXXFLAGS="-fPIC"
再次执行configure:
configrue --disable-shared
make
makeinstall
编译完成后,使用libprotobuf.a文件,以上问题解决。
解决方法:
php.ini中加载了两个扩展,都是使用了protobuf的同类扩展,把一个注释掉,只使用一个,问题解决。
相关文章推荐
- sftp与ftp用法
- php mb_strlen 获取字符串的长度
- php mb_substr 获取字符串的部分
- php7 php-fpm 显示空白页原因一例
- php try() catch() : 捕捉异常,抛出异常
- PHP内核探索:新垃圾回收机制说明
- Swagger PHP使用指南
- php 得到所选择的mysql数据库名称和链接信息
- ubuntu +phpstorm 配置phpunit
- PHP empty(),isset()与is_null()的实例测试
- 本机php环境搭建教程:windows环境…
- easyphp环境配置
- 只需要四步,就能完成PHP搭建
- Java调用PHP 实例
- php 引用(&)详解
- YII 页面缓存
- PHP/Java Bridge 实例 | PHP 调用 Java 实例
- php面向对象中static静态属性和静态方法的调用
- 关于“运行在主线程的ContentProvider为什么不会影响主线程”的记录
- 深入浅出讲解:php的socket通信