Adding Static Libcurl to Code::Blocks Ide

Adding static libcurl to Code::Blocks IDE

Okay, I managed to build your example successfully with libcurl using static linkage. The details involved to make this work are quite intricate -- setting it up correctly can get tricky for the unwary.

Here are the steps I used to make this work, be sure to follow them carefully:

  1. Go to Project build options->Compiler settings->#defines: type in CURL_STATICLIB. When this is defined the libcurl.h header will have its function signatures preprocessed to fit static linkage. Otherwise dynamic linkage is assumed and the mangled names then become _imp__*. The unresolved errors from your screenshot indicate it's attempting a dynamic link rather than the desired static link.

  2. Under Project build options->Linker settings->Link libraries make sure it contains the following: curl, rtmp, idn, ssl, ssh2, crypto, z, ws2_32, wldap32, winmm, gdi32. Note that order is important. Due to a design deficiency of the gnu linker, the most dependant libraries need to be listed first followed by least dependant. Other linkers like msvc link and borland's ilinker do not exhibit such issues -- the libraries can be listed in any order.

  3. Under Project build options->Linker settings->Other linker options add in '-static'. This will make sure that the static version of 'idn' is used. If this switch is omitted then your compiled program could depend on 'libidn-11.dll' to run which probably isn't what you want.

At this point, you should be able to compile and link libcurl programs without any issues. A couple things worth mentioning,

  • Under Other linker options the other extra switches from your screenshot aren't needed. 'libcurl.a' is already listed and covered by Link libraries.

  • The 'libcrypto.a' seems to cover the same references as the 'libeay32.a' so only one of them is needed. However, 'libeay32.a' causes dynamic linkage despite its larger size. If you want your application to be 'fully self-contained' use 'libcrypto.a' instead like in the screenshot.

  • If you wish to link dynamically in the future, just replace the listing with 'curldll' under Link libraries and remove the CURL_STATICLIB define. The extra libraries (eg. ssl, idn, rtmp etc.) aren't needed since libcurl.dll already covers them.

  • You can avoid the tedious error prone setup of a new libcurl program by employing codeblocks' user templates. (eg. File->New->Project->User templates)

Hopefully this resolves any build problems you have with libcurl once and for all.

Adding libcurl to Code::Blocks IDE on Ubuntu 14.04

sudo apt-get install curl installs the curl commandline tool and the libcurl shared library.
It does not install the header files for curl development (curl.h etc.) and it does not install
the static library, libcurl.a, to which you are trying to link.

You will find it much more convenient to link to the shared library, libcurl.so

  • At the console prompt run sudo apt-get install libcurl4-openssl-dev (to install the curl development headers).
  • In the C::B IDE:
    • Remove libcurl.a from Linker settings.
    • In the Linker settings -> Other linker options, enter -lcurl (instructing the linker to link libcurl.so) and OK out.

Then rebuild the example program.

Adding linker options to Code::Blocks

Never mind, i found the answer in this post
http://forums.codeblocks.org/index.php/topic,15998.0.html

To sum up, in Code Blocks, go to

"Settings" -> "Compiler and debugger..."
"Global compiler settings"
"Linker settings"

Then add the following options to `"Other linker options":

-static-libgcc -static-libstdc++

Then you are off to go...



Related Topics



Leave a reply



Submit