curl-library
Re: Build environment for C++ .net
Date: Mon, 14 Sep 2015 02:15:02 -0400
On 9/13/2015 4:26 PM, Jon wrote:
>
> Hi All,
>
> I’m starting to write an application in Microsoft Visual Studio 2012
> using C++ and .net. I attempted to compile and build with my prior
> libcurl.lib libarary/dependency that I was using in the same VS 2012
> but for C++ only (without .net) but I’m receiving all sorts of
> compiler warnings:
>
> (e.g. warning C4272: 'curl_free' : is marked __declspec(dllimport);
> must specify native calling convention when importing a function.)
>
> and also linker errors:
>
> (e.g. error LNK2031: unable to generate p/invoke for "extern "C" void
> __clrcall curl_easy_cleanup(void *)"
> (?curl_easy_cleanup@@$$J0YMXPAX_at_Z); calling convention missing in
> metadata)
>
> After looking around a little bit, it appears I’ll need a new lib/dll
> build specifically for C++ .net. I don’t need the code, just the
> libraries will do if you have them.
>
There's a .NET binding for libcurl, libcurl.NET [1]. It is very old from
ten years ago but it looks as though it still works. I suggest you make
a few modifications though. After you download and unzip replace the
bin/libcurl.dll with your own 32-bit libcurl.dll and replace
bin/ca-bundle.crt with the most recent version [2]. Then you can play
around with the samples. For more recent versions of Visual Studio
you'll have to add /platform:x86 when compiling, like this:
cd samples
csc /platform:x86 /r:../bin/LibCurlNet.dll /out:../bin/SSLGet.exe SSLGet.cs
cd ../bin
sslget https://encrypted.google.com
There's probably a way to do it with x64 but you would have to build the
shim on your own and change the naming of the libcurl DLL I think.
If you see this:
System.DllNotFoundException: Unable to load DLL 'libcurl.dll': The
operating sys
tem cannot run . (Exception from HRESULT: 0x800700B6)
It's because some DLL libcurl depends on can't be found. Like if your
libcurl links to OpenSSL you'll need those DLLs (libeay32.dll,
ssleay32.dll) in your path or copied to the bin directory.
Also take note of the comment/review on the libcurl.NET homepage [1]
about a memory leak if you are making a lot of requests.
[1]: http://sourceforge.net/projects/libcurl-net
[2]: https://github.com/bagder/ca-bundle/blob/master/ca-bundle.crt
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2015-09-14