libcurla编译
‘壹’ 如何链接libcurl
静态链接libcurl的步骤
1、使用跟程序相同的选项编译libcurl静态库;
2、程序中在引入curl头文件前定义
#define
CURL_STATICLIB
3、引入库:
#if defined(_DEBUG)
#pragma comment(lib,
"libcurld.lib")
#else
#pragma comment(lib,
"libcurl.lib")
#endif
#pragma comment ( lib, "ws2_32.lib" )
#pragma
comment ( lib, "wldap32.lib" )
‘贰’ 有没有人用过NDK编译libcurl的
我记得,在官方文档中 "Dev Guide" 部分的左下角有一小节是专门用来讲解 "NDK" 的,你不妨去看看
‘叁’ 为什么编译好的libcurl静态lib用不了
When building an application that uses the static libcurl library, you must
add -DCURL_STATICLIB to your CFLAGS. Otherwise the linker will look for
dynamic import symbols. If you get linker error like "unknown symbol
__imp__curl_easy_init ..." you have linked against the wrong (static)
library. If you want to use the libcurl.dll and import lib, you don't need
any extra CFLAGS, but use one of the import libraries below
在这里:http://curl.haxx.se/docs/faq.html#Link_errors_when_building_libcur
所以我们这样来改
菜单-->project -->settings-->C++选项卡的General里面的Project Option里面加上-DCURL_STATICLIB (其实就相当于在Preprocessor definitions里面加上CURL_STATICLIB一样)
确定-->rebuild all
又出错了:
libcurl.lib(easy.obj) : error LNK2001: unresolved external symbol
libcurl.lib(telnet.obj) : error LNK2001: unresolved external symbol
libcurl.lib(easy.obj) : error LNK2001: unresolved external symbol
.....
这个一看就明白了马上加上:
#pragma comment ( lib, "ws2_32.lib" )
#pragma comment ( lib, "wldap32.lib" )
编译-->叮的一个美妙的声音想起了,哈哈,编译成功
‘肆’ 如何编译libcurl
我是这样编的 :
① ./configure --prefix=/usr/local/gcc-4.1.2-glibc-2.5-nptl-3/arm-none-linux-gnueabi CC=/usr/local/gcc-4.1.2-glibc-2.5-nptl-3/arm-none-linux-gnueabi/bin/arm-none-linux-gnueabi-gcc --host=arm-linux
② 然后make ,
③ 接着 sudo make install
这样 就在/usr/local/gcc-4.1.2-glibc-2.5-nptl-3/arm-none-linux-gnueabi/lib 下面 看到libcurl.so ,
然后我要用这个libcurl.so 交叉编译一个c文件
④ arm-none-linux-gnueabi-gcc curl3.c -o curl0 -L. -lcurl
‘伍’ 如何在Visual Studio 2013中使用libcurl库
本文详细描述了如何编译libcurl源文件,如何在Visual Studio 2013中使用libcurl库,最后还给出了如何通过libcurl库根据URL下载对应的网页内容到本地的代码实例。
http://download.csdn.net/download/dongdongup/701
‘陆’ 如何编译libcurl
1. Android
1.1配置
将curl源文件加到在Android源代码external/curl/中。创建shell脚本configure.sh,并把它放到external/curl/中。
脚本内容如下:
#!/bin/sh SDK_ROOT=/home/nudtzxm/android_sdk export PATH="$SDK_ROOT/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin:$PATH" ./configure --host=arm-linux CC=arm-eabi-gcc \ CPPFLAGS="-I $SDK_ROOT/system/core/include -I $SDK_ROOT/hardware/libhardware/include -I $SDK_ROOT/hardware/libhardware_legacy/include -I $SDK_ROOT/hardware/ril/include -I $SDK_ROOT/dalvik/libnativehelper/include -I $SDK_ROOT/frameworks/base/include -I $SDK_ROOT/frameworks/base/opengl/include -I $SDK_ROOT/external/skia/include -I $SDK_ROOT/out/target/proct/generic/obj/include -I $SDK_ROOT/bionic/libc/arch-arm/include -I $SDK_ROOT/bionic/libc/include -I $SDK_ROOT/bionic/libstdc++/include -I $SDK_ROOT/bionic/libc/kernel/common -I $SDK_ROOT/bionic/libc/kernel/arch-arm -I $SDK_ROOT/bionic/libm/include -I $SDK_ROOT/bionic/libm/include/arch/arm -I $SDK_ROOT/bionic/libthread_db/include -I $SDK_ROOT/bionic/libc/kernel/common -I $SDK_ROOT/bionic/libc/kernel/arch-arm -I $SDK_ROOT/system/core/libcutils -I $SDK_ROOT/out/target/proct/generic/obj/STATIC_LIBRARIES/libcutils_intermediates -I $SDK_ROOT/out/target/proct/generic/obj/STATIC_LIBRARIES/libwebcore_intermediates -I $SDK_ROOT/system/core/include/arch/linux-arm/ -include $SDK_ROOT/system/core/include/arch/linux-arm/AndroidConfig.h" \ CFLAGS="-nostdlib -fno-exceptions -fpic -ffunction-sections -funwind-tables -fstack-protector -fno-short-enums -Wno-multichar -msoft-float -march=armv5te -mtune=xscale -D__ARM_ARCH_5__ -D__ARM_ARCH_5T__ -D__ARM_ARCH_5E__ -D__ARM_ARCH_5TE__ -mthumb-interwork -DANDROID -fmessage-length=0 -W -Wall -Wno-unused -Winit-self -Wpointer-arith -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -DSK_RELEASE -DNDEBUG -g -Wstrict-aliasing=2 -finline-functions -fno-inline-functions-called-once -fgcse-after-reload -frerun-cse-after-loop -frename-registers -DNDEBUG -UDEBUG -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64" \ LIBS="-L$SDK_ROOT/out/target/proct/generic/obj/lib -L$SDK_ROOT/out/target/proct/generic/obj/STATIC_LIBRARIES/libcutils_intermediates/libcutils.a -lc -lm -ldl $SDK_ROOT/prebuilt/linux-x86/toolchain/arm-eabi-4.4.0/bin/../lib/gcc/arm-eabi/4.4.0/interwork/libgcc.a"
进入到curl的根目录,运行这个脚本:
1.2 Make
进入curl的根目录,运行make curl命令:
1.3 参数配置
您可能会看到参数配置是复杂的。如何设置呢?你应该阅读curl/ Android.mk的注释。
2 iOS
我改变了参数的配置,所以配置命令是:
./configure –disable-shared –host=arm-apple-darwin10
3.视窗
打开的vc6curl.dsw,并选择“DLL Release”来编译。您会在CURL_ROOT\lib\DLL-Release
发现libcurl.dll和libcurl_imp.lib。
4.关于头文件
curl/include的头文件,只在成功配置后使用,头文件在不同的平台上是不同的。
‘柒’ libcurl库怎么编译到codeblocks中
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:
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.
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.
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.
‘捌’ libcurl是什么语言开发的
libcurl是C语言开发的网络库,支持多种网络协议.
有很多种不同的方式来编译C语言代码。这里使用UNIX平台下的编译方式。即使你使用的是其他的操作系统,你仍然可以通过阅读本文档来获取许多有用的信息。
编译
你的编译器必须知道libcurl头文件的位置。所以在编译的时候,你要设置头文件的包含路径。可以使用curl-config工具来获取这方面的信息:
$ curl-config –cflags
链接
编译完源码(这时的源代码不是指libcurl的源代码,你是你自己写的程序代码)之后,你还必须把目标文件链接成单个可执行文件。你要链接libcurl库,以及libcurl所依赖的其他库,例如OpenSLL库。当然可能还需要一些其他的操作系统库。最后你还要设置一些编译选项,当然可以使用curl-config工具简化操作:
$curl-config –libs
是否使用SSL
定制编译libcurl。与其他库不同的是,libcurl可以定制编译,根据实际需要是否支持某些特性,如是否支持SSL传输,像HTTPS和FTPS。如果决定需要支持SSL,必须在编译时正确的设置。可以使用’curl-config’来判断libcurl库是否支持SSL:
$ curl-config –feature
‘玖’ linux编libcurl库时依赖openssl怎么编
如果你在编译时遇到这个错误,这可能是下面的原因:你尝试编译的程序使用OpenSSL,但是需要和OpenSSL链接的文件(库和头文件)在你Linux平台上缺少。
要解决这个问题,你需要安装OpenSSL 开发包,这在所有的现代Linux发行版的标准软件仓库中都有。
要在Debian、Ubuntu或者其他衍生版上安装OpenSSL:
复制代码
代码如下:
$ sudo apt-get install libssl-dev
‘拾’ 如何编译libcurl
1:linux下源码编译
./configure --prefix=/usr/local/curl --disable-shared --enable-static --without-libidn --without-ssl --without-librtmp --without-gnutls --without-nss --without-libssh2 --without-zlib --without-winidn --disable-rtsp --disable-ldap --disable-ldaps --disable-ipv6
注意:不需要其它功能就disable,不然会在连接时报错, 如果你没有disable掉,但你的机器上又没有安装相应的库,link时会报错。
2:windows下源码编译
libcurl 7.21以后的版本在Windows下的编译比较简单,自带了MinGW和VC环境的Makefile文件,首先去Curl官网下载源代码:curl.haxx.se/download.html,任选一个下载即可,推荐这个: curl-7.21.2.tar.gz,下载完成后解压开,打开命令行进入curl源码目录,(在此之前请先设置好MinGW的环境变量):
cd curl-7.21.2
编译libcurl库文件:
cd lib
make -f Makefile.m32
等待编译完成即可
(若需编译生成curl可执行文件,则执行:
cd ../src
make -f Makefile.m32)
编译完成后,我们需要复制include头文件和库文件到一个目录供程序开发用
1. 新建curllib目录
2. 新建curllib/include目录,将源代码include目录里的curl文件夹复制到curllib/include目录,这些是使用libcurl需要的头文件
3. 新建curllib/lib目录,将源代码lib目录里编译好的库文件libcurl.a,libcurldll.a,libcurl.dll复制到curllib目录
4. 将MinGW安装目录下lib文件夹里的libwldap32.a和libws2_32.a复制到curllib/lib目录