【发布时间】:2019-02-19 05:19:49
【问题描述】:
我已经下载了 win xp 的 libcurl 窗口通用版本。我正在使用 c++ builder 2007。
我添加了 * 项目中的 curl\include 文件夹->选项->路径和定义->[包含路径] * 项目中的 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 安装文件夹中没有这样的文件。
请建议如何解决。
更新:我使用Borland\RAD Studio\5.0\bin>implib -a libcurl.lib libcurl.dll 得到libcurl.lib 并且项目没有抱怨libcurl.lib 但现在它需要libcrypto-1_1-x64.dll 文件(“应用程序无法启动,因为libcrypto-1_1 -x64.dll 未找到。重新安装应用程序可能会解决问题“由 BCB 引发的错误”。
我尝试从 Internet 下载 libcrypto-1_1-x64.dll 文件,但我得到“应用程序或 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 位应用程序。
有什么建议吗?
【问题讨论】:
-
"但libcurl安装文件夹中没有'libcurl.lib'文件"可能是因为你有libcurl源代码,所以你需要编译它才能得到lib库文件?
-
我已经用我在解决方案上的进展更新了这个问题。请检查您是否可以帮助我解决“应用程序无法启动,因为找不到 libcrypto-1_1-x64.dll。重新安装应用程序可能会解决问题”错误已解决。
-
链接器需要查找 lib 文件。动态库是不同的——它们需要在您执行程序时位于路径上,或者有时与程序位于同一文件夹中。查找静态链接与动态链接。
-
这对我来说有点新鲜。我曾尝试在项目中添加
libcurl.dll,但没有帮助。那么我应该如何使用libcurl.dll(或libcurl.lib?)进行静态链接(我知道应该删除#pragma .. 行,因为这是动态链接) -
我曾尝试在删除
#pragma comment(lib, "C:\Dev\Curl\bin\libcurl.lib")后在项目中添加libcurl.lib文件,但没有帮助并引发同样的错误。
标签: c++ c++builder libcurl vcl