【PHP】libphpcpp.so编译

    在本地增加了一个新的php扩展后,遇到依赖的libphpcpp.so没有装上,于是自己来编译安装

    $ php -v
    
    PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/Cellar/php70/7.0.20_12/lib/php/extensions/no-debug-non-zts-20151012/thriftphp.so' - dlopen(/usr/local/Cellar/php70/7.0.20_12/lib/php/extensions/no-debug-non-zts-20151012/thriftphp.so, 9): Library not loaded: libphpcpp.so.2.0
    
    Referenced from: /usr/local/Cellar/php70/7.0.20_12/lib/php/extensions/no-debug-non-zts-20151012/thriftphp.so
    
    Reason: image not found in Unknown on line 0
    
    Warning: PHP Startup: Unable to load dynamic library '/usr/local/Cellar/php70/7.0.20_12/lib/php/extensions/no-debug-non-zts-20151012/thriftphp.so' - dlopen(/usr/local/Cellar/php70/7.0.20_12/lib/php/extensions/no-debug-non-zts-20151012/thriftphp.so, 9): Library not loaded: libphpcpp.so.2.0
    
    Referenced from: /usr/local/Cellar/php70/7.0.20_12/lib/php/extensions/no-debug-non-zts-20151012/thriftphp.so
    
    Reason: image not found in Unknown on line 0
    
    PHP 7.0.20 (cli) (built: Jun 23 2017 07:46:30) ( NTS )
    
    Copyright (c) 1997-2017 The PHP Group
    
    Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies



    安装步骤:

    1、Clone代码库

    git clone https://github.com/CopernicaMarketingSoftware/PHP-CPP.git

    2、Mac下需要安装XCode,并运行安装组件

    3、Mac下修改编译,修改Makefile 119行

    LINKER_FLAGS            =   -shared

    修改为

    LINKER_FLAGS            =   -shared -undefined dynamic_lookup

    如不修改就进行编译会遇到以下错误

    Undefined symbols for architecture x86_64:
      "_OnUpdateString", referenced from:
          Php::Ini::fill(_zend_ini_entry_def*, int) in ini.o
    …
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    make: *** [libphpcpp.so.2.0.0] Error 1

    4、修改Makefile 179行

     ${LINKER} ${PHP_LINKER_FLAGS} -Wl,-soname,libphpcpp.so.$(SONAME) -o $@ ${COMMON_SHARED_OBJECTS} ${PHP_SHARED_OBJECTS}

    修改为

     ${LINKER} ${PHP_LINKER_FLAGS} -Wl,-install_name,libphpcpp.so.$(SONAME) -o $@ ${COMMON_SHARED_OBJECTS} ${PHP_SHARED_OBJECTS}

    5、make & make install

    等运行成功,再来运行看看php -v,不报错了,搞定。

    参考文章:

    1. How to install PHP-CPP
    2. Compile error under mac...


    本博客所有文章如无特别注明均为原创。
    复制或转载请以超链接形式注明转自枫芸志,原文地址《【PHP】libphpcpp.so编译
    标签:
    分享:

还没有人抢沙发呢~

无觅相关文章插件,快速提升流量