您好,欢迎来到锐游网。
搜索
您的当前位置:首页curl之编译

curl之编译

来源:锐游网

一、编译前工作

1、常规编译

./../curl-7.76.1/configure --prefix=/opt/curl-7.76.1-ubuntu-x64 --with-ssl --enable-tls-srp

2、交叉编译

# 设置交叉编译工具链到环境变量
export PATH=/opt/tools-master/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin:$PATH

# 设置OpenSSL依赖项到环境变量
export OPENSSL_ROOT=/opt/openssl-1.1.1k-raspberrypi-armv7l
export LD_LIBRARY_PATH=$OPENSSL_ROOT/lib:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=$OPENSSL_ROOT/lib/pkgconfig:$PKG_CONFIG_PATH
export PATH=$OPENSSL_ROOT/bin:$PATH
export CPATH=$OPENSSL_ROOT/include:$CPATH
export LIBRARY_PATH=$OPENSSL_ROOT/lib:$LIBRARY_PATH

./../curl-7.76.1/configure --host=arm-linux-gnueabihf --prefix=/opt/curl-7.76.1-raspberrypi-armv7l--with-ssl --enable-tls-srp

3、注意项

  • 如果是进行交叉编译,则需要先把交叉编译工具链添加到环境变量,然后设置--host选项,指定交叉编译工具链命令的前缀,生成的Makefile文件中会将使用到的编译工具补全成arm-linux-gnueabihf-gcc或者arm-linux-gnueabihf-ar等。
  • 如果启动了--with-ssl选项,则必须先安装openssl库,。

二、编译安装

三、环境配置

        设置环境变量,编辑/etc/profile文件,末尾添加:

export CURL_ROOT=/opt/curl-7.76.1-ubuntu-x64
# 运行依赖
export LD_LIBRARY_PATH=$CURL_ROOT/lib:$LD_LIBRARY_PATH
# 开发依赖
export PATH=$CURL_ROOT/bin:$PATH
export CPATH=$CURL_ROOT/include:$CPATH
export LIBRARY_PATH=$CURL_ROOT/lib:$LIBRARY_PATH
export PKG_CONFIG_PATH=$CURL_ROOT/lib/pkgconfig:$PKG_CONFIG_PATH # 需要同步修改pkgconfig目录下libcurl.pc文件中的prefix路径,指定为当前的库路径

四、番外(Windows下编译和环境配置)

1、编译

(1)方法1

        通过CMake(cmake-gui)构建Visual Studio工程,然后再打开工程编译出库。此处省略一万字…

(2)方法2

        请先在系统中安装Visual Studio 6以上版本,本机使用的是Visual Studio 2019,在开始菜单打开所要编译的架构,如这里选择x86

nmake /f Makefile.vc mode=<static or dll> <options>

2、环境配置

        设如果在Windows下编译安装好了curl,使用CMake构建其他工程时,若需要依赖curl,则需要配置环境变量:

3、常见错误

(1)链接错误:error LNK2001: 无法解析的外部符号 __imp_ldap_init
1>libcurl.lib(ldap.obj) : error LNK2001: 无法解析的外部符号 __imp_ldap_init
1>libcurl.lib(ldap.obj) : error LNK2001: 无法解析的外部符号 __imp_ldap_unbind_s
1>libcurl.lib(ldap.obj) : error LNK2001: 无法解析的外部符号 __imp_ldap_set_option
1>libcurl.lib(ldap.obj) : error LNK2001: 无法解析的外部符号 __imp_ldap_simple_bind_s
1>libcurl.lib(ldap.obj) : error LNK2001: 无法解析的外部符号 __imp_ldap_search_s
1>libcurl.lib(ldap.obj) : error LNK2001: 无法解析的外部符号 __imp_ldap_msgfree
1>libcurl.lib(ldap.obj) : error LNK2001: 无法解析的外部符号 __imp_ldap_err2string
1>libcurl.lib(ldap.obj) : error LNK2001: 无法解析的外部符号 __imp_ldap_first_entry
1>libcurl.lib(ldap.obj) : error LNK2001: 无法解析的外部符号 __imp_ldap_next_entry
1>libcurl.lib(ldap.obj) : error LNK2001: 无法解析的外部符号 __imp_ldap_first_attribute
1>libcurl.lib(ldap.obj) : error LNK2001: 无法解析的外部符号 __imp_ldap_next_attribute
1>libcurl.lib(ldap.obj) : error LNK2001: 无法解析的外部符号 __imp_ldap_get_values_len
1>libcurl.lib(ldap.obj) : error LNK2001: 无法解析的外部符号 __imp_ldap_value_free_len
1>libcurl.lib(ldap.obj) : error LNK2001: 无法解析的外部符号 __imp_ldap_get_dn
1>libcurl.lib(ldap.obj) : error LNK2001: 无法解析的外部符号 __imp_ldap_memfree
1>libcurl.lib(ldap.obj) : error LNK2001: 无法解析的外部符号 __imp_ber_free

方案: 给工程添加依赖的库:项目右键–>属性–>配置属性–>链接器–>输入–>附加依赖项,把 ws2_32.libwinmm.libwldap32.lib添加进去。

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- ryyc.cn 版权所有

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务