<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ## 前言 在本文,我們將建立一個簡單的lib靜態庫,并在擴展中進行封裝調用。 ## 代碼 ### 基礎代碼 這個擴展,我們將在say擴展上增加`show_site_ar()`。say擴展相關代碼大家請看這篇博文。PHP7擴展開發之hello word 文中已經詳細介紹了如何創建一個擴展和提供了源碼下載。 ### 代碼實現 #### 建立lib庫 增加hello.h文件。代碼如下: ```c #ifndef TEST_HEADER_FILE #define TEST_HEADER_FILE #include <stdlib.h> #include <string.h> char * show_site(); #endif ``` 增加hello.c文件。代碼如下: ```c #include "hello.h" char * show_site() { char *site = malloc(15 * sizeof(char)); strcpy(site, "www.bo56.com"); return site; } ``` 然后使用以下命令生成lib庫(動態庫)文件: ``` $ gcc -c -o ./hello.o ./hello.c $ ar -r hello.a hello.o ``` 這樣在當前目錄下就會生成一個`hello.so`的動態庫文件。不同操作系統動態庫的擴展名可能不一樣。如 windows下是dll,mac下是 dylib,linux下是so。 然后把`ar -r hello.a hello.o`拷貝到`/usr/local/lib/`目錄下,命名為`hello.a` 把`hello.h`拷貝到`/usr/local/include/`目錄下。 #### 修改config.m4文件 增加擴展對動態庫的依賴。主要增加以下幾行代碼: ``` PHP_ADD_LIBRARY_WITH_PATH(hello, /usr/local/lib/, SAY_SHARED_LIBADD) PHP_SUBST(SAY_SHARED_LIBADD) ``` #### 修改Makefile文件 執行phpize命令后,會生成Makefile文件。修改文件如下: 把 ``` SAY_SHARED_LIBADD = -Wl,-rpath,/usr/local/lib/ -L/usr/local/lib/ -lhello ``` 修改為 ``` SAY_SHARED_LIBADD = -Wl,-rpath,/usr/local/lib/ -L/usr/local/lib/ /usr/local/lib/hello.a ``` 即,把-lhello修改為了具體的靜態庫路徑。 #### 編寫擴展代碼 增加hello.h的引用。 ``` #include "php_say.h" #include <stdio.h> //下面這行是增加的 #include "hello.h" ``` 增加show_site()方法。代碼如下: ``` PHP_FUNCTION(show_site_ar) { char *site = show_site(); RETVAL_STRING(site); free(site); return; } ``` php調用結果 ``` <?php $result = show_site_ar(); var_dump($result); ?> ``` 執行結果 ``` $php ./test.php string(12) "www.bo56.com" ``` ## 代碼解讀 `PHP_ADD_LIBRARY_WITH_PATH` 是用于指定lib庫的名字,地址等信息。第一個參數是名字,第二個參數是地址。 在`say.c`文件中增加lib庫的頭文件。使用`#include "hello.h"`。 在擴展代碼中就像調用其他內核提供的方法一樣,去調用lib庫中的方法。 關于config.m4文件的說明請查看 http://php.net/manual/zh/internals2.buildsys.configunix.php
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看