c++静态链接旋度

C++ Link Curl Statically

本文关键字:链接 静态 c++      更新时间:2023-10-16

我在DEV c++环境中使用这段代码。

#include <stdio.h>
#include <curl/curl.h>
#include <iostream>
using namespace std;
int main(void){
  CURL *curl;
  CURLcode res;
  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "http://google.com");
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
    curl_easy_setopt(curl, CURLOPT_USERAGENT, "TestAgent");
    res = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
  }
  system("pause");
  return 0;
}

我已经链接了libcurllll。A和libcurl。一个文件。我可以编译和运行代码,但可执行文件需要msvcr70.dll和libcurl.dll在同一目录下。我如何静态地链接它们?

看看curl-config工具。它提供了一个选项来获取用于构建静态链接的libcurl的链接器标志和依赖项:

——static-libs

显示了完整的库集和您需要的其他链接器选项将应用程序与libcurl静态地链接起来。(在7.17.1中添加)

为此,您需要在您的环境中从源代码构建libcurl。