简体   繁体   中英

What's the proper way of using libcURL without the dlls?

recently managed to use a libcurl in a test program for downloading a files. The code is this:

  CURL * curl;
  FILE * fout;
  CURLcode result;
  char * url = "http://blablabla.com/blablabla.txt";
  char filename[FILENAME_MAX] = "blablabla.txt";
  curl = curl_easy_init();
  if (curl)
  {
    fout = fopen(filename,"wb");
    curl_easy_setopt(curl, CURLOPT_URL, url);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, fout);
    result = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
    fclose(fout);
  }

and those things for directives:

#define CURL_STATICLIB
#include <curl/curl.h>

My question is how to make that I don't need to copy all of its dlls in the same dir with the exec to make it work:

libcurl.dll
libeay32.dll
libidn-11.dll
librtmp.dll
libssh2.dll
libssl32.dll
zlib1.dll

Cannot find info about that in the homesite (http://curl.haxx.se) of the library :|

You mean, "how do I statically link libcurl"?

5.7 in the FAQ says:

When building an application that uses the static libcurl library, you must add -DCURL_STATICLIB to your CFLAGS . Otherwise the linker will look for dynamic import symbols. If you're using Visual Studio, you need to instead add CURL_STATICLIB in the "Preprocessor Definitions" section.

CURL *curl;
CURLcode res;
CString strUser;
FILE *ftplister;
m_FTPUserName.GetWindowTextW (strUser);
CT2CA PUF_File_HostName(PUF_FIle_Host);
CT2CA FTP_UserName(FTP_USERNAME);
FTP_PASSWORD.Append(L":");
FTP_PASSWORD.Append(FTP_USERNAME);
CT2CA FTP_Password(FTP_PASSWORD);
CT2CA FTP_AddressName(FTP_Address);
CString strLocalFile;
CString strFileName;
m_FTPFileName.GetWindowTextW(strFileName);
strLocalFile.Append(FTP_FileName);
strLocalFile.Append(L"\\");
strLocalFile.Append(strFileName);
CT2CA PUF_LocalFile(strLocalFile);
//ofstream stream2(PUF_LocalFile);

curl = curl_easy_init();
if(curl)
{
    ftplister=fopen(PUF_LocalFile,"wb");
    curl_easy_setopt(curl,CURLOPT_URL,PUF_File_HostName);
    if(strUser!=_T(""))
    {
    curl_easy_setopt(curl,CURLOPT_USERPWD,FTP_Password);
    }
    curl_easy_setopt(curl, CURLOPT_FTP_SSL, TRUE);
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, &write_data);
    curl_easy_setopt(curl, CURLOPT_WRITEDATA, ftplister);
    res = curl_easy_perform(curl);
    curl_easy_cleanup(curl);
    fclose(ftplister);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM