0

I am trying to get libcurl to work. I am using libcurl for the first time. I installed libcurl using vcpkg.

C:\Users\infib\vcpkg>vcpkg install curl
The following packages are already installed:
curl[core,ssl,tool,winssl]:x86-windows 
Starting package 1/1: curl:x86-windows
Package curl:x86-windows is already installed
Elapsed time for package curl:x86-windows: 4.298 ms

Total elapsed time: 4.956 ms

The package curl:x86-windows provides CMake targets:

find_package(CURL CONFIG REQUIRED)
target_link_libraries(main PRIVATE CURL::libcurl)

I installed opencv64 bit and I am trying to use libcurl but I am getting many errors.

error LNK2019: unresolved external symbol __imp_curl_easy_init
error LNK2019: unresolved external symbol __imp_curl_easy_setopt 
error LNK2019: unresolved external symbol __imp_curl_easy_perform 
error LNK2019: unresolved external symbol __imp_curl_easy_cleanup 
error LNK2019: unresolved external symbol __imp_curl_easy_getinfo

1>libcurl_a.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type    'x64'
1>libcurl-d.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
1>libcurl.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
1>WINMM.LIB : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
1>wldap32.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
1>ws2_32.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'

Could some one tell me how to over come this error. I included libcurl.lib that I found in vcpkg packages folder but still I am getting this error. I tried all the methods mentioned in stackover flow libcurl thread but still I am getting the errors.

Please let me know how to solve this.

1 Answers1

0

It looks like the core of your issue is x64 vs x86. vcpkg likely is pulling in the x86 build. Honestly the solution I used was to pull the source for curl directly and use cmake. Once you have the source you need to run a script like this (in the curl directory):

mkdir build32 pushd build32 cmake -G "Visual Studio 16 2019" -A Win32 .. popd cmake --build build32 // this will compile it for you

mkdir build64 pushd build64 cmake -G "Visual Studio 16 2019" -A x64 .. popd cmake --build build64 // same as above

this will make a shared library. If you want a static lib you will need to go into the CMakeLists.txt file and update

option(BUILD_SHARED_LIBS "Build shared libraries" ON)

to

option(BUILD_SHARED_LIBS "Build shared libraries" OFF)

which will enable a static build.

you will find the necessary .lib and .dll files under the respective build lib and type folder e.g. debug 64 would be build64\lib\Debug

hope this helps.

  • https://cmake.org/cmake/help/git-stage/generator/Visual%20Studio%2016%202019.html – Mathew Upchurch Feb 04 '20 at 18:44
  • Hey Matthew, welcome to Stack Overflow. In the future, it probably makes more sense to put suggestions in the comments and then wait to post an answer until you have worked through it. If you are going to work through the answer after posting it, I'd recommend updating your answer instead of making piece-meal updates to it. – Jeremy Caney Feb 04 '20 at 19:24
  • updated answer and removed comments I made as it confuses the issue. – Mathew Upchurch Feb 05 '20 at 20:16