Implementing libcurl: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
(correction, simplification)
Line 1: Line 1:
== What is libcurl? ==
{{toc-right}}


[http://curl.haxx.se/libcurl/ libcurl] is a free and easy-to-use client-side URL transfer library that allows you to transfer files across the internet through various protocols such as HTTP. It is the base of [http://curl.haxx.se/ cURL] a very popular command line tool for transferring data.
'''[http://curl.haxx.se/libcurl/ libcurl]''' is a free library that can download data from the internet. It supports just about every protocol imaginable, and is available [http://curl.haxx.se/docs/copyright.html under a MIT/X derivative license].


A few examples of the things that you could do by implementing libcurl into your source engine mod would be to set up an in game poll, download game content, upload player data. The possibilities are endless.
== Implementation ==


== The Installation ==
=== Windows ===


You will need to download the latest version of cURL. You can do this by visiting the [http://curl.haxx.se/latest.cgi?curl=zip Download page] on their website.
# [http://curl.haxx.se/latest.cgi?curl=zip Download the latest version of libcurl.]
# Extract the <code>\lib</code> and <code>\include</code> folders to a convenient location.
# Open libcurl's VS project and change it to Release mode.
# Go to ''libcurl > Properties > C/C++ > Preprocessor > Definitions'' and add <code title="The official docs say -DCURL_STATICLIB...they are wrong!">CURL_STATICLIB</code>. Unless you really do want to use [[wikipedia:LDAP|LDAP]], and <code>HTTP_ONLY</code> too.
# Go to ''libcurl > Properties > C/C++ > Code Generation > Runtime Library'' and change it to read <code>Multi-threaded (/MT)</code>.
# '''Build libcurl.'''
# Add <code>libcurl.lib</code> to your main project. The easiest way is to drag it onto the Solution Explorer.
# Go to ''Your Project > Properties > C/C++ > Preprocessor > Definitions'' and add <code title="The official docs say -DCURL_STATICLIB...they are wrong!">CURL_STATICLIB</code>, as you did to curl itself.
# Go to ''Your Project > Linker > Input > Additional Dependencies'' and add <code>ws2_32.lib</code>. If you want to use LDAP, add <code>wldap32.lib</code> as well.
# Go to ''Your Project > Properties > C/C++ > General > Additional Include Directories'' and add the libcurl <code>\include</code> folder you extracted earlier.
# <code>#include "curl/curl.h"</code> and start coding! <code>curl/easy.h</code> is helpful too.


Proceed to extract the zip and open your mod folder, and your mods solution in VS.
{{note|Remember that you will need to repeat steps 8-10 in both Release and Debug configurations.}}


In your modname\src\ folder create a new folder named libcurl.
=== Linux ===


Open the curl folder that you just extracted, browse to curl-#.##.#\lib and copy all of the files in there.
{{todo}}


Paste them into your new modname\src\libcurl folder.
== Usage ==
 
Back in the your recently extracted curl folder browse to curl-#.##.#\include and copy the curl folder into your modname\src\libcurl folder.
 
Now include the modname\src\libcurl\curl include files into your client project.
 
In VS right click your solution, select Add -> Existing Project. Select modname\src\libcurl\libcurl.vcproj.
 
VS2008 and 2010 only: Run through the conversion wizard.
 
Open your client projects properties, go to Configuration Properties -> C/C++ -> General, Open "Additional Include Directories" and add the following to the bottom of the list.
..\..\libcurl\curl
 
Go to Configuration Properties -> C/C++ -> Preprocessor, Open "Preprocessor Definitions" and add the following to the bottom of the list.
  CURL_STATICLIB
 
Go to Configuration Properties -> Linker -> Input, Open "Ignore Specific Library" and add the following to the bottom of the list.
  msvcrt
 
Open your libcurl projects properties, go to Configuration Properties -> C/C++ -> Code Generation, Change "Runtime Library" to
Multi-threaded (/MT)
 
Go to Configuration Properties -> C/C++ -> Preprocessor, Open "Preprocessor Definitions" and add the following to the bottom of the list.
CURL_STATICLIB
HTTP_ONLY
And remove the following from the list.
_USRDLL
 
You are now ready to build libcurl.
 
Once its done building navigate to modname\src\libcurl\Release and copy libcurl.lib over to modname\src\lib\public.
 
You are now ready to use libcurl! Stop by the [http://curl.haxx.se/libcurl/c/example.html Examples page] to get started.
 
If you need any extra help feel free to hit me up on steam. --[[User:DaFox|DaFox]]
 
== The curl license ==
libcurl is licensed under a MIT/X derivative license
 
COPYRIGHT AND PERMISSION NOTICE
Copyright (c) 1996 - 2010, Daniel Stenberg, <daniel@haxx.se>.
All rights reserved.
Permission to use, copy, modify, and distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright
notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of a copyright holder shall not
be used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization of the copyright holder.


* [http://curl.haxx.se/libcurl/c/ The libcurl C API]
* [http://curl.haxx.se/libcurl/c/example.html Some examples]


[[Category:Programming]]
[[Category:Programming]]
[[Category:Free source code]]
[[Category:Free source code]]

Revision as of 06:58, 6 September 2010

libcurl is a free library that can download data from the internet. It supports just about every protocol imaginable, and is available under a MIT/X derivative license.

Implementation

Windows

  1. Download the latest version of libcurl.
  2. Extract the \lib and \include folders to a convenient location.
  3. Open libcurl's VS project and change it to Release mode.
  4. Go to libcurl > Properties > C/C++ > Preprocessor > Definitions and add CURL_STATICLIB. Unless you really do want to use LDAP, and HTTP_ONLY too.
  5. Go to libcurl > Properties > C/C++ > Code Generation > Runtime Library and change it to read Multi-threaded (/MT).
  6. Build libcurl.
  7. Add libcurl.lib to your main project. The easiest way is to drag it onto the Solution Explorer.
  8. Go to Your Project > Properties > C/C++ > Preprocessor > Definitions and add CURL_STATICLIB, as you did to curl itself.
  9. Go to Your Project > Linker > Input > Additional Dependencies and add ws2_32.lib. If you want to use LDAP, add wldap32.lib as well.
  10. Go to Your Project > Properties > C/C++ > General > Additional Include Directories and add the libcurl \include folder you extracted earlier.
  11. #include "curl/curl.h" and start coding! curl/easy.h is helpful too.
Note.pngNote:Remember that you will need to repeat steps 8-10 in both Release and Debug configurations.

Linux

[Todo]

Usage