I'm trying for several days to get libcurl working with my project and I'm getting insane with it. I'm acting as it is written in instructions and I get errors all the time. This is what I do step by step:
https://curl.haxx.se/dlwiz/ on this website in download wizard I picked option "Source code" then "Platform Independent" (because I couldn't find windows here) and downloaded the file.
I launched "Developer Command Prompt for VS 2017" got into C:\Users\PC\Downloads\curl-7.58.0\curl-7.58.0\winbuild using "cd" command and then typed (I'm not sure about VC=17 option - in instruction they say that the value for it can be from <9,15>, but there wasn't any error when I type 17) "nmake /f Makefile.vc mode=static VC=17 DEBUG=yes MACHINE=x64" and get error as below:
"..\builds\libcurl-vc15-x64-debug-static-ipv6-sspi-winssl-obj-lib/file.obj : fata l error LNK1112: wystąpił konflikt typu maszyny modułu "x86" z typem maszyny doc elowej "x64" NMAKE : fatal error U1077: ""C:\Program Files (x86)\Microsoft Visual Studio\2017 \Community\VC\Tools\MSVC\14.12.25827\bin\HostX86\x86\link.exe"": kod powrotu "0x 458" Stop. NMAKE : fatal error U1077: ""C:\Program Files (x86)\Microsoft Visual Studio\2017 \Community\VC\Tools\MSVC\14.12.25827\bin\HostX86\x86\nmake.exe"": kod powrotu "0 x2" Stop. "
telling something about conflict of module machine type "x86" with target machine "x64" - wierd because my machine is 64bit (Windows 7 64bit).
I've tried once again with machine changed to x86: "nmake /f Makefile.vc mode=static VC=17 DEBUG=yes MACHINE=x86" - I get no error(wierd, because I think that previous error should occur now
Then I went to "C:\Users\PC\Downloads\curl-7.58.0\curl-7.58.0\builds\libcurl-vc17-x86-debug-static-ipv6-sspi-winssl", where I found 3 folders: bin, include, lib.
I created new visual studio 2017 empty project. Created source file and pasted an example code I had found on internet:
#include <stdio.h>
#include <curl/curl.h>
int main(void)
{
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);
}
return 0;
}
in Solution Explorer->MyProject->Properties(configuration-debug, platform- win32)->Configuration Properties->C/C++->Additional Include Directories - I added here path: C:\Users\PC\Downloads\curl-7.58.0\curl-7.58.0\builds\libcurl-vc17-x86-debug-static-ipv6-sspi-winssl\include
then in Configuration Properties -> Linker -> General -> Additional Library Directories - I added: C:\Users\PC\Downloads\curl-7.58.0\curl-7.58.0\builds\libcurl-vc17-x86-debug-static-ipv6-sspi-winssl\lib
and then in Configuration Properties -> Linker -> Input -> Additional Dependencies I added the name of generated *.lib file from the folder above - libcurl_a_debug.lib
Finally, I clicked on Build -> Build solution and in the "Output" window I get:
1>------ Build started: Project: libcurltest, Configuration: Debug x64 ------ 1>Source.cpp 1>Source.obj : error LNK2019: unresolved external symbol __imp_curl_easy_strerror referenced in function main 1>Source.obj : error LNK2019: unresolved external symbol __imp_curl_easy_init referenced in function main 1>Source.obj : error LNK2019: unresolved external symbol __imp_curl_easy_setopt referenced in function main 1>Source.obj : error LNK2019: unresolved external symbol __imp_curl_easy_perform referenced in function main 1>Source.obj : error LNK2019: unresolved external symbol __imp_curl_easy_cleanup referenced in function main 1>C:\Users\PC\source\repos\libcurltest\Dependencies\lib\libcurl_a_debug.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64' 1>C:\Users\PC\source\repos\libcurltest\x64\Debug\libcurltest.exe : fatal error LNK1120: 5 unresolved externals 1>Done building project "libcurltest.vcxproj" -- FAILED. ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
It looks like the linker couldn't see my library despite that I've added it. What could be a problem?
EDIT: If I added #define CURL_STATICLIB on the begining of Source.cpp it now compiles , but I still don't understand why I couldn't compile libcurl for x64 platform