💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# C开发者如何使用Swoole swoole使用cmake来做编译配置,示例程序在examples/server.c中。 您可以在此基础上进行代码开发。 如果需要修改编译细节的选项,请直接修改CMakeLists.txt 生成config.h ---- swoole依赖`phpize`和`configure`检测系统环境,生成`config.h` ```shell cd swoole-src/ phpize ./configure ``` 执行成功后`swoole-src`目录下会有`config.h` Build & Install ----- ```bash cmake . make make install ``` * `cmake`命令可以增加`cmake . -DCMAKE_INSTALL_PREFIX=/opt/swoole`参数指定安装的路径 * `make`命令可以使用 `make DESTDIR=/opt/swoole install`参数指定安装的路径 安装路径非系统默认的lib目录时,需要配置`ld.so.conf`将swoole动态连接库所在的目录添加到link路径中。 ```shell #需要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头即可。 ```c #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 ```