在Windows10上使用gcc编译器编译c程序时,如何将库与文件链接
在阅读其他堆栈溢出问题时,我遇到了curl库的this下载链接,该库具有curl.h头文件
当我试图编译这个文件时,我得到了这个错误
C:\Users\0000\Desktop>gcc simple.c -lcurl
simple.c:2:10: fatal error: curl/curl.h: No such file or directory
2 | #include <curl/curl.h>
| ^~~~~~~~~~~~~
compilation terminated.我也试过这一行
gcc simple.c我也试过了,但我一直收到这个错误
cl simple.c 这显然是一个库链接问题
#include <stdio.h>
#include <curl/curl.h>
int main(void)
{
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com");
/* 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));
/* always cleanup */
curl_easy_cleanup(curl);
}
return 0;
}发布于 2021-02-06 23:27:24
测试使用'-L‘的gcc标志。这将接收目录,其中是库的文件。
示例: gcc simple.c -L curlDownloadDirectory -lcurl
发布于 2021-02-07 04:03:53
您需要libcurl.a (链接的部分)和curl.h (包含的头文件),但还必须告诉编译器/链接器在哪里查找头文件(-I <path>),在哪里查找库(-L )。您可以有多个-I和-L规范。
https://stackoverflow.com/questions/66078257
复制相似问题