2017-09-14 206 views
0

我在Mac OSX 10.12.6版上构建libcurl时遇到了一些严重问题。在32位支持和自定义OpenSSL版本的MacOSX上构建libcurl

我需要一个具有32位体系结构支持的特定版本的静态库(7.40.0),它与特定版本的OpenSSL(1.0.2c)链接。

我发现在官方网站的源代码,并跑了这在我看来,正确的参数配置脚本:

curl-7.40.0> CPPFLAGS="-I/Users/me/Documents/Projects/3rdparty/openssl/MacOSX/openssl-1.0.2c/include/" 
LDFLAGS="-L/Users/Documents/Projects/3rdparty/openssl/MacOSX/openssl-1.0.2c/" 
./configure --disable-shared --build=i386-darwin --with-ssl 

其中:

  • CPPFLAGS声明OpenSSL的文件夹头;
  • LDFLAGS指定OpenSSL库的文件夹(libssl.a,libcrypto.a);
  • --disable-shared禁用动态库的构建(没有libcurl.dylib输出);
  • --build=i386-darwin为Apple 32位目标体系结构配置构建;
  • --with-ssl启用SSL选项。

然而,这一呼吁有两个原因失败:

  1. 在配置输出看,我读了“host system type”设置为i386-darwin,作为目标。我可以通过指定--host=x86_64-darwin来解决这个问题;
  2. 我得到的SSL实际上是没有启用:

    configure: WARNING: SSL disabled, you will not be able to use HTTPS, FTPS, NTLM and more. 
    configure: WARNING: Use --with-ssl, --with-gnutls, --with-polarssl, --with-cyassl, --with-nss, --with-axtls, --with-winssl, or --with-darwinssl to address this. 
    

我当然可以通过指定--with-darwinssl解决这个问题,但是当我做,我得到以下警告:

ld: warning: directory not found for option '-L/Users/me/Documents/Projects/3rdparty/openssl/MacOSX/openssl-1.0.2c' 

我试图链接的OpenSSL库被忽略。

最后,如果我尝试删除CFLAGSLDFLAGS的SSL(只是为了看看最简单的通话作品):

./configure --build=i386-darwin --disable-shared --with-darwinssl 

当我这样做时,configuremake脚本有好下场的。如果我尝试包括在示例源代码curl标题:

#import <Foundation/Foundation.h> 
#include "curl/curl.h" 

,并指定了XCode头搜索路径curl-7.40.0/include目录,我得到的语义问题:

curl-7.40.0/include/curl/curlrules.h:143:6: '__curl_rule_01__' declared as an array with a negative size 
curl-7.40.0/include/curl/curlrules.h:153:6: '__curl_rule_02__' declared as an array with a negative size 

我发现这个问题描述here 。如果我去检查curlbuild.h#define s,我发现CURL_SIZEOF_LONG是8,但是明确定义。该项目是与架构i386编译。

最后,如果我尝试更多的事情简单化,并运行一个不可知论者:

./configure --disable-shared --with-darwinssl 

,并切换示例项目架构回到通用32/64位,当我联系,我收到了一堆怪异的错误:

"_ber_free", referenced from: 
"_inflate", referenced from: 
"_inflateEnd", referenced from: 
"_inflateInit2_", referenced from: 
"_inflateInit_", referenced from: 
"_ldap_err2string", referenced from: 
"_ldap_first_attribute", referenced from: 
"_ldap_first_entry", referenced from: 
"_ldap_free_urldesc", referenced from: 
"_ldap_get_dn", referenced from: 
"_ldap_get_values_len", referenced from: 
"_ldap_init", referenced from: 
"_ldap_memfree", referenced from: 
"_ldap_msgfree", referenced from: 
"_ldap_next_attribute", referenced from: 
"_ldap_next_entry", referenced from: 
"_ldap_search_s", referenced from: 
"_ldap_set_option", referenced from: 
"_ldap_simple_bind_s", referenced from: 
"_ldap_unbind_s", referenced from: 
"_ldap_url_parse", referenced from: 
"_ldap_value_free_len", referenced from: 
"_zlibVersion", referenced from: 

我可能在这里丢失了一些明显的东西,或者错过了许多小砖块。无论哪种方式,我完全失去了,我想知道我的任务是否真的可行。

我可以“重新编译”在64位的整个应用程序,但我可能需要这个版本的libcurl版本的OpenSSL,如果我甚至不能得到一个示例应用程序去有没有点切换到真实的东西(如果您对我为什么需要此配置感到好奇,请检查my other thread about libcurl problems:Windows客户端没有连接问题并正在使用上述配置)。

您是否看到我正在做的任何明显的错误?任何帮助或照明问题将不胜感激。

回答

0

我实际上错过了很多步骤,但让我们按照时间顺序来解决问题。

1)OpenSSL的编译

我重建OpenSSL和在我的文档文件夹中安装了它,运行:

./configure no-shared --openssldir=~/Documents/openssl-lib darwin-i386-cc 
make 
make install 

安装步骤中添加的 “LIB” 文件夹中的链接需要。

2)编译libcurl

之前实际编制libcurl我必须安装pkg-config

brew install pkg-config 

然后,我给了正确的配置命令:

CPPFLAGS="-I/Users/me/Documents/openssl-lib -I/Users/me/Documents/openssl-lib/include" 
LDFLAGS="-L/Users/me/Documents/openssl-lib/lib" LIBS="-ldl -lpthread" 
CFLAGS="-arch i386" 
./configure --with-ssl=/Users/me/Documents/openssl-lib 
    --disable-sharing -build=i386-darwin 

现在openssl选项是正确的配置,因为:

  1. pkg-config已安装;
  2. 我加了一个CFLAGS -arch i386

一旦与正确的OpenSSL版本的链接...

的工作还没有完成!因为我仍然需要在我的测试应用程序中链接二进制文件。除了libcurl我不得不链接

  1. openssl(是的,再次)
  2. LDAP(的XCode包括一个框架)
  3. zlib(增加了 “其他编译器选项” -lz

后其中,我的测试程序与Cloudfront正确连接并显示正确curl版本。