Trying to work with the C ++ curl library in the windows form C ++ project

CURL *curl; CURLcode result; //инициализируем curl curl = curl_easy_init(); 

On the line curl = curl_easy_init(); errors start as if lib is not connected. In the windows form, how else do the lib components connect? Connected through the program and the project settings did not help. visual studio 2010 C ++ /

1> CurlFormTest.obj: error LNK2031: Could not create P or Invoke for "extern" C "enum CURLcode __clrcall curl_global_init (long)" (? Curl_global_init @@ $$ J0YM? AW4CURLcode @@ J @ Z); there is no calling agreement in the metadata

1> CurlFormTest.obj: error LNK2028: link to the unresolved (0A00001A) lexeme "extern" C "enum CURLcode __clrcall main (cli :: array ^) "(? main @@ $$ HYMHP $ 01AP $ AAVString @ System @@@ Z)

When they answered my question, everything turned out, but when I ran into such a problem again I forgot how to fix it and read again the answer was difficult to find the right setting, so I decided for myself and others to make a graphical hint, here. enter image description here After setting the curl works. Attention for Debug and Ralase Nasta need to separately. In my opinion it is better to choose realase

  • I won’t say about the curl, but in .NET you can use the WebClient , WebRequest , HttpClient , and RestSharp classes instead. - Alexander Petrov
  • one
    Before using, you must first call curl_global_init(CURL_GLOBAL_ALL) , and see if it returns an error. - enshirokov 5:02 pm
  • 1> CurlFormTest.obj: error LNK2031: Could not create P or Invoke for "extern" C "enum CURLcode __clrcall curl_global_init (long)" (? Curl_global_init @@ $$ J0YM? AW4CURLcode @@ J @ Z); In the metadata, there is no calling convention 1> CurlFormTest.obj: error LNK2028: link to unresolved token (0A00001A) "extern" C "enum CURLcode __clrcall ) in the function "int __clrcall main (cli :: array <class System :: String ^> ^)" (? main @@ $$ HYMHP $ 01AP $ AAVString @ System @@@ Z) ... - Yuriy Pysanka

1 answer 1

In C ++ / CLI projects compiled with the /clr:pure or /clr:safe option , the default calling convention is clrcall , not cdecl. Therefore, libraries that do not explicitly state the calling convention (but imply cdecl) in the header files in the function declaration do not work. You need to either compile with the /clr parameter (without pure / safe), or declare all the necessary CURL functions manually.

See Linker Tools Error LNK2031

  • and where to specify when compiling the library / clr (without pure / safe) - Yuri Pysanka
  • @Yu.Pysanka In the properties of the project, General (Common) - Common Language Runtime Support (Support for common language runtime) - MSDN.WhiteKnight
  • To the addition after these actions, the curl simply did not compile - Yuri Pysanka
  • @YurіyPysanka you collect it from the source or as a DLL connect? What error does it display? - MSDN.WhiteKnight
  • one
    @YurіyPysanka In the project in which you collect curl from source, of course you do not need to set the /clr parameter (you don’t need to change anything at all, return to the last state in which it was compiled). I meant, you need to set this parameter in the win forms project that uses it. - MSDN.WhiteKnight