c++ - curl_easy_getinfo undefined symbol 错误

标签 c++ curl undefined asterisk symbols

我使用的是 asterisk 版本 13.5.0。在 utils 目录中,我创建了一个名为 curl_util 的新模块,其源代码如下:

#include "asterisk/curl_utils.h"
HttpResponse * httpResponseNew()
{
    HttpResponse * response = calloc(1, sizeof(HttpResponse));

    return response;
error:
    return NULL;
}

HttpResponse * httpRequestPost(char *url, char *post_body, size_t size)
{
    struct MemoryStruct chunk;
    CURL *curl = curl_easy_init();

    chunk.memory = malloc(1);
    chunk.size = 0;

    HttpResponse *response = httpResponseNew();
    curl_easy_setopt(curl, CURLOPT_URL, url);
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0);
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0);
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 0);
    curl_easy_setopt(curl, CURLOPT_POST, 1L);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, post_body);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, size);
    curl_easy_setopt(curl, CURLOPT_TIMEOUT, 30);
    curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, HttpResponseMemoryWriter);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);

    response->res = curl_easy_perform(curl);

    if (response->res != CURLE_OK)
    {
        response->OK = 0;
    }
    else
    {
        response->OK = 1;
        response->size = chunk.size;
        response->body = chunk.memory;
    }

    curl_easy_cleanup(curl);

    return response;

error:
    free(chunk.memory);
    if (curl) curl_easy_cleanup(curl);
    return response;
}

在chan_sip.c中,我调用了上面提到的httpRequestPost函数。 执行make和make install就OK了。 但是,当启动 dahdi 和 asterisk 时,出现以下错误:

加载模块 chan_sip.so 时出错: undefined symbol :httpRequestPost

loader.c: 无法加载模块 chan_sip.so。

能否请您提供提示或建议来修复此错误? 提前谢谢你。

最佳答案

不需要编辑 makefile。您只需要使用 ASTLDFLAGS 编译器选项,例如:

./configure
make ASTLDFLAGS="-lcurl"
make install
make samples
make config

关于c++ - curl_easy_getinfo undefined symbol 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32113027/

相关文章:

c++ - 编辑 ListView 控件项

java - 发布到服务器的 HttpPost 参数返回 HTTP 500 错误

使用 curl 的 xml-rpc 请求?

C++如何检查char变量是否未定义(未初始化)

C++ 非类型模板参数 const char*

c++ - Typedefs、(二进制)代码复制和目标文件

php - 努力用 PHP 抓取 asp.net

Javascript对象属性未定义(但属性已设置)

javascript - 隐藏或删除图像 src=undefined

c++ - 带协商的 Telnet 客户端服务器 session