<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                [TOC] > [參考](http://www.bkjia.com/Linux/964805.html) ## 創建一個 .so 文件 ## 1. 創建`hello.c` ``` int hello_add(int a, int b) { return a + b; } ``` ## 2. 編譯 ``` $ gcc -O -c -fPIC -o hello.o hello.c $ gcc -shared -o libhello.so hello.o $ su # echo /usr/local/lib > /etc/ld.so.conf.d/local.conf # cp libhello.so /usr/local/lib # /sbin/ldconfig ``` ## 3. 驗證是否正確加載 創建 `hellotest.c` ``` #include <stdio.h> int main() { int a = 3, b = 4; printf("%d + %d = %d\n", a, b, hello_add(a,b)); return 0; } ``` 執行 ``` $ gcc -o hellotest -lhello hellotest.c # -lhello 編譯時加入動態so 文件 $ ./hellotest 3 + 4 = 7 ``` > 在 CentOS 下可以正常編譯 ## 4. 下載php 源碼 進入`ext` ``` $ ./ext_skel --extname=hello $ cd hello ``` ## 5. 修改 `config.m4` `去掉第16行和第18行的注釋(注釋符號為 dnl )` ``` 16: PHP_ARG_ENABLE(hello, whether to enable hello support, 17: dnl Make sure that the comment is aligned: 18: [ --enable-hello Enable hello support]) ``` ``` $ phpize ``` ## 6. 修改` php_hello.h` 在文件后尾添加 ``` PHP_FUNCTION(hello_add); ``` ## 7. 編輯`hello.c` ``` zend_function_entry hello_functions[] = { PHP_FE(confirm_hello_compiled, NULL) /* For testing, remove later. */ PHP_FE(hello_add, NULL) /* 此處添加要實現的方法 */ {NULL, NULL, NULL} /* Must be the last line in hello_functions[] */ }; //文末,添加具體實現 PHP_FUNCTION(hello_add) { longint a, b; longint result; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &a, &b) == FAILURE) { return; } result = hello_add(a, b); RETURN_LONG(result); } ``` ## 8. 編譯安裝 ``` $ phpize $ ./configure --with-php-config=/www/server/php/56/bin/php-config $ make clean # 清除編譯 $ make LDFLAGS=-lhello #-lhello 表示加載 動態庫 libhello.so 文件 $ sudo make install ``` 在`php.ini`加入`extension=hello.so` ## 9. 測試 `php -r"echo hello_add(3, 4);"` //輸出7 或者使用`php hello.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>

                              哎呀哎呀视频在线观看