gpt4 book ai didi

c++ - 如何在 C++ Builder 中使用 libcurl

转载 作者:行者123 更新时间:2023-12-02 10:39:16 25 4
gpt4 key购买 nike

我已经下载了 win xp 的 libcurl 窗口通用版本。我正在使用 c++ builder 2007。

我添加了
* 项目中的 curl\include 文件夹->选项->路径和定义->[包含路径]
* Project->Options->Paths and Defines->[Library path] 中的 curl\lib 文件夹

我用 main.h 创建了一个简单的项目作为:

#ifndef mainH
#define mainH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <curl/curl.h>
#include <curl/easy.h>
#include <stdio.h>
//---------------------------------------------------------------------------
class TForm3 : public TForm
{
__published: // IDE-managed Components
TButton *Button1;
void __fastcall Button1Click(TObject *Sender);
private: // User declarations
public: // User declarations
__fastcall TForm3(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm3 *Form3;
//---------------------------------------------------------------------------
#endif

和 main.cpp 为:
#include <vcl.h>
#pragma hdrstop

#include "main.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
//#pragma comment(lib, "C:\Dev\Curl\bin\libcurl.dll")
//#pragma comment(lib, "C:\Dev\Curl\lib\libcurl.a")
//#pragma comment(lib, "C:\Dev\Curl\lib\libcurl.dll.a")
TForm3 *Form3;
//---------------------------------------------------------------------------
__fastcall TForm3::TForm3(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm3::Button1Click(TObject *Sender)
{
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);
}
}
//---------------------------------------------------------------------------

当我运行程序时,我得到一个链接器错误:
[ILINK32 Error] Error: Unresolved external '_curl_easy_init' referenced from C:\DOCUMENTS AND SETTINGS\VATISH\DESKTOP\LIBCURLDEMO\DEBUG\MAIN.OBJ
[ILINK32 Error] Error: Unresolved external '_curl_easy_setopt' referenced from C:\DOCUMENTS AND SETTINGS\VATISH\DESKTOP\LIBCURLDEMO\DEBUG\MAIN.OBJ
[ILINK32 Error] Error: Unresolved external '_curl_easy_perform' referenced from C:\DOCUMENTS AND SETTINGS\VATISH\DESKTOP\LIBCURLDEMO\DEBUG\MAIN.OBJ
[ILINK32 Error] Error: Unresolved external '_curl_easy_strerror' referenced from C:\DOCUMENTS AND SETTINGS\VATISH\DESKTOP\LIBCURLDEMO\DEBUG\MAIN.OBJ
[ILINK32 Error] Error: Unresolved external '_curl_easy_cleanup' referenced from C:\DOCUMENTS AND SETTINGS\VATISH\DESKTOP\LIBCURLDEMO\DEBUG\MAIN.OBJ

根据我的搜索,我需要 libcurl.lib文件以满足链接器,但在 libcurl 安装文件夹中没有这样的文件。

请建议如何解决。

更新 : 我得到 libcurl.lib使用 Borland\RAD Studio\5.0\bin>implib -a libcurl.lib libcurl.dll并且项目没有提示 libcurl.lib但现在它想要 libcrypto-1_1-x64.dll文件(“应用程序无法启动,因为找不到 libcrypto-1_1-x64.dll。重新安装应用程序可能会解决问题”由 BCB 引发的错误)。
我试过下载 libcrypto-1_1-x64.dll来自 Internet 的文件,但我得到“应用程序或 DLL\Borland\RAD Studio\5.0\bin\libcrypto-1_1-x64.dll 不是有效的 Windows 镜像。”

更新 2:我已尝试添加 libcurl.lib动态和静态,但我仍然面临同样的错误,即“应用程序无法启动,因为找不到 libcrypto-1_1-x64.dll。重新安装应用程序可能会解决问题”。

注:我正在使用 Window XP 32 位,我的应用程序是 32 位应用程序。

有什么建议吗?

最佳答案

大约一周前,我下载了几个 zip 文件,并使用 tdump 查看了 dll 导入。其中一个 zip 文件从 64 位 libcrypto-1_1-x64.dll 文件( objective-c PU 类型 80386)导入。

我今天下载并测试,它正确地从 libcrypto-1_1.dll 导入。

正确版本的 zip 文件目前在 Windows 文件夹中的大小为 2966Kb,在属性中为 2.89Mb,在网站上为 2.9Mb。

明智的注意事项:- 32 位和 64 位版本具有不同的 dll 名称。

  • Win 32 是 libcurl.dll
  • Win 64 是 libcurl-x64.dll
  • 关于c++ - 如何在 C++ Builder 中使用 libcurl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52331212/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com