ThinkSSL🔒 一键申购 5分钟快速签发 30天无理由退款 购买更放心 广告
# C开发者如何使用Swoole [TOC] swoole使用cmake来做编译配置,示例程序在examples/server.c中。 您可以在此基础上进行代码开发。 如果需要修改编译细节的选项,请直接修改CMakeLists.txt ## 生成config.h swoole依赖`phpize`和`configure`检测系统环境,生成`config.h` ~~~ cd swoole-src/ phpize ./configure ~~~ 执行成功后`swoole-src`目录下会有`config.h` ## Build & Install ~~~ cmake . make make install ~~~ * `cmake`命令可以增加`cmake . -DCMAKE_INSTALL_PREFIX=/opt/swoole`参数指定安装的路径 * `make`命令可以使用`make DESTDIR=/opt/swoole install`参数指定安装的路径 安装路径非系统默认的lib目录时,需要配置`ld.so.conf`将swoole动态连接库所在的目录添加到link路径中。 ~~~ #需要root权限 echo "/opt/swoole/lib" >> /etc/ld.so.conf #或者 echo "/opt/swoole/lib" > /etc/ld.so.conf.d/swoole.conf #更新动态连接库信息 ldconfig ~~~ ## Example 示例代码:examples/server.c 在C代码中只需要引入swoole头即可。 ~~~ #include <swoole/Server.h> #include <swoole/Client.h> int main() { swServer serv; swServer_create(&serv); serv.onStart = my_onStart; ... swServer_start(&serv); } ~~~ 编译运行 ~~~ gcc -o server server.c -lswoole ./server ~~~