C、<curl/curl.h>没有链接

C, <curl/curl.h> not linking

我有一个 1 个文件的 C 程序,如下所示,它正在尝试进行简单的 CURL 调用。还有一个简单的Make文件。

看起来我的 curl/curl.h 没有被链接进来,导致所有对 *curl 的引用都是错误的。

我用自制软件安装了 Curl。 我是否需要为链接器指定确切的位置位置?

代码

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

int main(void) {
    Curl *curl = curl_easy_init();

    if(!curl) {
        printf("curl init failed");
        return 1;
    }

    curl_easy_setopt(curl, CURLOPT_URL, "https://api.coinbase.com/v2/prices/BTC-USD/buy");

    CURLcode result = curl_easy_perform(curl);

    if(result != CURLE_OK) {
        printf("curl peform fail");
    }

    curl_easy_cleanup(curl); 
 
  return 0;
}

错误

name@name-MacBook-Pro c % make

gcc -o main main.c -lcurl 

main.c:10:5: error: use of undeclared identifier 'Curl'

Curl *curl = curl_easy_init();
^ main.c:10:11: error: use of undeclared identifier 'curl'

Curl *curl = curl_easy_init();
      ^ main.c:12:9: error: use of undeclared identifier 'curl'

if(!curl) {
    ^ main.c:17:22: error: use of undeclared identifier 'curl'

curl_easy_setopt(curl, CURLOPT_URL, "https://api.coinbase.com/v2/prices/BTC-USD/buy");
                 ^ main.c:19:41: error: use of undeclared identifier 'curl'

CURLcode result = curl_easy_perform(curl);
                                    ^ main.c:25:23: error: use of undeclared identifier 'curl'

curl_easy_cleanup(curl); 
                  ^ 6 errors generated. make: *** [all] Error 1

如果安装了 CURL 检查

name@name-MacBook-Pro c % curl --version curl 7.64.1 (x86_64-apple-darwin19.0) libcurl/7.64.1 (SecureTransport) LibreSSL/2.8.3 zlib/1.2.11 nghttp2/1.39.2 Release-Date: 2019-03-27 Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp Features: AsynchDNS GSS-API HTTP2 HTTPS-proxy IPv6 Kerberos Largefile libz MultiSSL NTLM NTLM_WB SPNEGO SSL UnixSockets

您应该使用 CURL,而不是 Curl。


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

int main(void) {
    CURL *curl = curl_easy_init();

    if(!curl) {
        printf("curl init failed");
        return 1;
    }

    curl_easy_setopt(curl, CURLOPT_URL, "https://api.coinbase.com/v2/prices/BTC-USD/buy");

    CURLcode result = curl_easy_perform(curl);

    if(result != CURLE_OK) {
        printf("curl peform fail");
    }

    curl_easy_cleanup(curl); 

    return 0;
}