I have a problem with compiling DLL in C++. I am using CURL library for HTTP POST.
When I compile my code as Console App, I do not get compile errors. But that same code gets Unresolved external symbol errors.
Lines like:
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
curl_easy_setopt(...);
curl_mime_name(...);
What I am doing wrong with dll? What is missing?
Here is the the code:
// dllmain.cpp : Defines the entry point for the DLL application.
#define CURL_STATICLIB
#include "pch.h"
#include "CURL/curl.h"
#pragma comment (lib, "CURL/libcurl_a.lib")
__declspec(dllexport) int httpPOST();
BOOL APIENTRY DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
int httpPOST() {
CURL* curl;
CURLcode res;
curl_global_init(CURL_GLOBAL_DEFAULT);
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist* headers = NULL;
headers = curl_slist_append(headers, "Cookie: cmslog=1");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_mime* mime;
curl_mimepart* part;
mime = curl_mime_init(curl);
part = curl_mime_addpart(mime);
curl_mime_name(part, "username");
curl_mime_data(part, "user", CURL_ZERO_TERMINATED);
part = curl_mime_addpart(mime);
curl_mime_name(part, "requestcode");
curl_mime_data(part, "123456", CURL_ZERO_TERMINATED);
}
return 0;
}
Code inside httpPOST() compiles without problems in console app.
Errors are:
Error LNK2001 unresolved external symbol __imp__curl_global_init
Error LNK2001 unresolved external symbol __imp__curl_easy_init
Error LNK2001 unresolved external symbol __imp__curl_easy_setopt
Error LNK2001 unresolved external symbol __imp__curl_slist_append
Error LNK2001 unresolved external symbol __imp__curl_mime_init
...
Error LNK1120 8 unresolved externals
CURL/libcurl_a.libis correct ? - WhozCraigCURL/libcurl_a.libis correct, I have checked it again. @Jean-MarcVolle @WhozCraig - look_up