cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: use libcurl source files directly rather than link with library

From: Adam Light <aclight_at_gmail.com>
Date: Tue, 17 May 2011 11:31:49 -0700

On Mon, May 16, 2011 at 2:06 PM, Tom Bishop, Wenlin Institute
<tangmu_at_wenlin.com> wrote:
> Dear libcurl Users,
>
> Is it possible to use libcurl by compiling its source files together with my application's source files, rather than first building libcurl as a library and then linking with the library?
>

Possible? Yes. Simple? I guess that's for you to decide.

I see in this thread Daniel's suggestion of how you should do this. He
may be right. I decided to take an approach similar to yours so that
it would be possible for me to debug libcurl related code while
running my application in debug mode. It may (and probably is)
possible to do this using his suggestion of compiling libcurl as a
library and statically linking to it. So if you can get things working
that way, it's probably the best way. If not, here's how I do it.

I should first note that my application (named Igor) compiles on Mac
using Xcode and Windows using Visual Studio 2008. I have pasted below
the text of a README file I wrote the describes what I did originally
and how I upgrade to a new libcurl version. It is a bit convoluted but
hopefully you can get the idea. To clarify the instructions a bit,
config-macosx.h and curl_components_config.h are files that I have
created. The instructions describes what they contain.

The instructions below mention that I alter the curl_config.h file
that is created by the configure script. Here is my altered version.
MACIGOR and WINIGOR are definitions that are defined for my
application on Macintosh and Windows, respectively.

---- begin curl_config.h ---

#include "curl_components_config.h"

#ifdef MACIGOR
        #include "config-macosx.h"
#endif // MACIGOR

#ifdef WINIGOR
        #include "config-win32.h"

        // The config-win32.h file does not define the
        // following macros, which we want to have defined
        // so that the Windows and Macintosh versions
        // have the same functionality. To avoid modifying
        // config-win32.h, we add those here.
        
        /* if zlib is available */
        #define HAVE_LIBZ 1
        /* if you have the zlib.h header file */
        #define HAVE_ZLIB_H 1

#endif // WINIGOR

---- end curl_config.h ---

-- begin instructions

----------------------------------
-- Configuring libcurl --
----------------------------------

libcurl uses #define statements in header files to configure which
protocols (such as ftp, http, ldap, sftp, etc) and options are
enabled and disabled.

On operating systems that support shell scripting (such as OS X
and Linux), these options are typically controlled by passing the
appropriate flags to the configure script at the command line. This
script then creates a header file that contains the appropriate #defines.
Unfortunately, Windows does not support the configure script, so
libcurl ships with a different header file that is used on Windows
that uses default options. By default, almost all of the functionality
of libcurl is enabled. Because Igor does not support using most of
this, it makes the executable larger than necessary without adding
any beneift.

To change which libcurl options are enabled and disabled when it
is used with Igor, follow the steps below:

1. Download the libcurl source code. Instructions are given
below in the Upgrading libcurl section. Make sure that you extract
the libcurl source code into a different directory than your
Igor/LibcurlSrc directory.

2. Using Mac OS X, open a terminal window and change into
the root libcurl directory of the download. This is the directory
that contains the configure shell script.

3. Make a backup copy of the include/curl/curlbuild.h file in the Igor
source code working copy. After running configure, we'll use this backup
file to replace the curlbuild.h file that configure spits out.

4. Execute the following line:
configure --disable-debug --enable-static --disable-shared
--disable-crypto-auth --disable-ldap --disable-ldaps --disable-rtsp
--disable-proxy --disable-dict --disable-telnet --disable-tftp
--disable-pop3 --disable-imap --disable-smtp --disable-gopher
--disable-manual --disable-ipv6 --disable-sspi --disable-crypto-auth
--disable-cookies --without-ssl --without-gnutls --without-polarssl
--without-nss --without-ca-bundle --without-libssh2 --without-librtmp
--without-libidn --enable-threaded-resolver

5. Once the configure script has completed, there should be
a new or updated file in the /lib directory named curl_config.h

6. Open the curl_config.h file in a text editor such as TextEdit
or even XCode.

7. The top part of the file should contain a number of #defines,
many of which will be commented out, that control the libcurl features.
Here are some examples of these:
        #define CURL_DISABLE_COOKIES 1
        /* #undef ENABLE_IPV6 */
        
        Select all of these and overwrite the similar set of #defines in the
        LibcurlSrc/curl_components_config.h file.
        
8. Most of the rest of the header file contains Mac OS X specific macros.
This code should be copied and pasted into config-macosx.h, replacing
the similar code there.

9. Replace include/curl/curlbuild.h with the (original) backup version
of include/curl/curlbuild.h you created in step 3. If you skip this step
then there won't be problems on the Macintosh but the Libcurl library
will fail to compile on Windows.

10. Replace the contents of the curl_config.h file with something similar
to the code below:
#include "curl_components_config.h"

#ifdef MACIGOR
        #include "config-macosx.h"
#endif // MACIGOR

#ifdef WINIGOR
        #include "config-win32.h"

        // Add any additional definitions here that are
        // in the config-macosx.h file but not in the
        // config-win32.h file and which we want to be
        // defined. For example, HAVE_ZLIB_H and
        // HAVE_LIBZ.
#endif // WINIGOR

----------------------------------
-- Upgrading libcurl --
----------------------------------

To upgrade the version of libcurl in the Igor source code repository,
follow these steps:

1. Download libcurl. You can get the source code either by
using the git version control system (http://git-scm.com/)
or by downloading an archive (http://curl.haxx.se/download.html)
and extracting it. I recommend downloading the archive.
For the directions below, I assume that you've called the
directory containing the new unarchived libcurl files newlibcurl.

2. Extract the archive into a directory that is *not* the
Igor source code directory.

3. Once extracted, follow steps 2-4 in the Configuring libcurl
section above.

4. Copy the config-macosx.h and curl_components_config.h files
from your Igor source code working copy into the newlibcurl/lib directory.

5. Copy the macros in the newlibcurl/lib/curl_config.h file, generated
by the configure script, into the config-macosx.h and curl_components_config.h
files as directed by steps 5-8 in the Configuring libcurl section above.

6. Copy the curl_config.h file from your Igor source code working copy
into the newlibcurl/lib directory.

7. Now that you have configured libcurl, copy all of the .c and .h files
from the newlibcurl/lib directory into the IgorSource/LibcurlSrc directory,
overwriting the files that are already there.

8. Copy all of the .h files from the newlibcurl/include/curl directory
into the IgorSource/LibcurlSrc/include/curl directory.

9. Replace include/curl/curlbuild.h with the (original) backup version
of include/curl/curlbuild.h you created in step 3 of the Configuring
libcurl section above. If you skip this step then there won't be problems
on the Macintosh but the Libcurl library will fail to compile on Windows.

10. Check in IgorSource/LibcurlSrc to make sure that you didn't
accidentally copy any non-source code files such as Makefiles, .in
files, Perl scripts (.pl), or shell scripts (.sh) into the Igor
working copy.

-- end instructions --

I hope this helps
Adam
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-05-17