【问题标题】:Can't compile libcurl with Codeblocks IDE in Ubuntu无法在 Ubuntu 中使用 Codeblocks IDE 编译 libcurl
【发布时间】:2018-02-24 05:54:17
【问题描述】:

我正在尝试在 Ubuntu 上的 Codeblocks 16.01 中编译此代码,但它返回错误消息,未定义对“curl_easy_init”的引用

但是当我在终端 gcc -L/usr/lib/x86_64-linux-gnu main.c -o curl -lcurl 中运行时,不会返回任何错误。

我该如何解决这个问题?

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

void fileUpload()
{
    CURL *curl;
    CURLcode res;

    curl = curl_easy_init();
    if(curl) {
        curl_easy_setopt(curl, CURLOPT_URL,"http://test1:test1@www.idehn.tec.ac.cr/geoserver/rest/layers.xml");
        /* example.com is redirected, so we tell libcurl to follow redirection */
        curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

        /* Perform the request, res will get the return code */
        res = curl_easy_perform(curl);
        /* Check for errors */
        if(res != CURLE_OK)
            fprintf(stderr, "curl_easy_perform() failed: %s\n",
                    curl_easy_strerror(res));

        FILE* file = fopen( "layers.txt", "w");

        curl_easy_setopt( curl, CURLOPT_WRITEDATA, file) ;

        /* Perform the request, res will get the return code */
        res = curl_easy_perform(curl);
        /* Check for errors */
        if(res != CURLE_OK)
            fprintf(stderr, "curl_easy_perform() failed: %s\n",
                    curl_easy_strerror(res));

        /* always cleanup */
        curl_easy_cleanup(curl);

        fclose(file);
    }
}


int main() {

    //Call to the method that charge the url content to a file with all the layers.
    fileUpload();
    return 0;
}

【问题讨论】:

    标签: c linux curl codeblocks


    【解决方案1】:

    我想你忘了告诉代码块链接到libcurl

    • 构建选项...
    • 链接器设置
    • 添加(按钮)
    • 输入curl

    在此处查看图片:https://stackoverflow.com/a/5881751/1212012

    【讨论】:

    • 谢谢,最后我通过在链接器设置 -> 其他链接器选项上添加 -lcurl 使它工作
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-04
    • 2016-06-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多