gpt4 book ai didi

php - swig 和 libcurl 在一起

转载 作者:行者123 更新时间:2023-11-28 06:05:21 25 4
gpt4 key购买 nike

我正在学习制作 PHP 扩展,我偶然发现了一篇关于 swig 的博文。我尝试使用 libcurl 创建代码,但无法编译它。

%{
#include <stdio.h>
#include <curl/curl.h>

bool wsper(char* url, char* postdata){
CURL* curl = curl_easy_init();
CURLcode res;
if(curl){
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postdata);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false);
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
res = curl_easy_perform(curl);
if(res == CURLE_OK){
curl_easy_cleanup(curl);
return true;
}else{
return false;
}
}else{
return false;
}
}
%}

%module wsper
extern bool wsper(char* url, char* postdata);

运行以下命令后我没有遇到任何错误

swig -php file.c
g++ `php-config --includes` -fpic -lcurl -lcurlpp -c
wsper_wrap.c g++ -shared file_wrap.o -o file.so

但是当我尝试运行 php 文件时,出现错误提示:

undefined symbol: curl_easy_perform in Unknown line 0

最佳答案

您的链接器扩充是错误的。在使用 -c 调用 g++ 时使用 -lcurl -lcurlpp 调用 g++。

调用-shared 和-o file.so 时需要使用-fpic -lcurl -lcurlpp。

即最终链接应该是:

g++ -shared file_wrap.o -o file.so  -lcurl -lcurlpp

关于php - swig 和 libcurl 在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32492242/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com