如何在windows 10中使用gcc链接库?
在Windows 10上使用gcc编译器编译c程序时,如何将库与文件链接 在阅读其他堆栈溢出问题时,我遇到了curl库的下载链接,该库具有如何在windows 10中使用gcc链接库?,c,curl,gcc,C,Curl,Gcc,在Windows 10上使用gcc编译器编译c程序时,如何将库与文件链接 在阅读其他堆栈溢出问题时,我遇到了curl库的下载链接,该库具有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>
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.
cl simple.c
我也试过了,但我一直都有这个错误
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.
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;
}
#包括
#包括
内部主(空)
{
卷曲*卷曲;
卷曲编码;
curl=curl_easy_init();
if(curl){
curl\u easy\u setopt(curl,CURLOPT\u URL,“http://example.com");
/*com被重定向,所以我们告诉libcurl遵循重定向*/
卷曲位置(卷曲,卷曲位置,1L);
/*执行请求,res将获得返回代码*/
res=旋度(curl)\u容易执行(curl);
/*检查错误*/
如果(res!=卷曲(OK)
fprintf(stderr,“curl\u easy\u perform()失败:%s\n”,
卷曲(容易的);
/*总是清理*/
旋度\轻松\清洁(旋度);
}
返回0;
}
测试使用'-L'gcc标志。这将接收库文件所在的目录
示例:gcc simple.c-L curlDownloadDirectory-lcurl您需要libcurl.a(链接的部分)和curl.h(包含的头文件),但您还必须告诉编译器/链接器在何处查找头文件(
-I
)以及在何处查找库(-L)。您可以有多个-I
和-L
规范。“这显然是一个库链接问题”——不,不是。请看一下编译过程中的各个部分。查看头文件的使用位置。(步骤1),查看链接器的调用位置(步骤4)。错误是编译器找不到头文件并停止。看看gcc的“-I”标志或cl的“/I”标志,看看如何解决这个问题。“但我一直遇到这个错误”:什么错误-这不是一个错误,看起来像是试图使用不同的编译器。你真的有这个库吗?如果您使用的是MinGW/gcc:(它有大量的依赖项——这不是微不足道的)。