xcode 在 iOS 上使用 curl,我无法链接多个架构,CurlchkszEQ 宏失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21681954/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
using curl on iOS, I am unable to link with multiple architectures, CurlchkszEQ macro failing
提问by Howard Shere
I have built numerous versions of curl using the wonderful "build_curl" script i found on GitHub. I have also rebuild curl using other techniques.
我使用在 GitHub 上找到的美妙的“build_curl”脚本构建了许多版本的 curl。我还使用其他技术重建 curl。
But I always end up with the same issue.
但我总是以同样的问题告终。
I have an iOS project which links against curl. I can build and debug on the simulator (clearly using i386). I can build and debug with a device as long as I choose to only build the current architecture and the device is plugged in when I build.
我有一个与 curl 链接的 iOS 项目。我可以在模拟器上构建和调试(显然使用 i386)。我可以使用设备进行构建和调试,只要我选择仅构建当前架构并且在构建时插入设备即可。
However, if I choose to try to build Release OR if I choose to build Debug for 'iOS Device' with no device plugged in. I always end up with the following error:
但是,如果我选择尝试构建 Release 或者如果我选择在没有插入设备的情况下为“iOS 设备”构建 Debug。我总是以以下错误告终:
curlrules.h:143:6: '__curl_rule_01__' declared as an array with a negative size
This is caused by this:
这是由以下原因引起的:
#define CurlchkszEQ(t, s) sizeof(t) == s ? 1 : -1
typedef char
__curl_rule_01__
[CurlchkszEQ(long, CURL_SIZEOF_LONG)];
This #define exists in curlbuild.h
这个 #define 存在于 curlbuild.h
#define CURL_SIZEOF_LONG 4
Which should be correct, because I am building for a 32 bit architecture, however, Xcode has decided that sizeof(long) != 4
, and so the Macro generates an error.
这应该是正确的,因为我正在为 32 位架构构建,但是,Xcode 已经决定了sizeof(long) != 4
,因此宏会生成错误。
I have chosen to only build for armv7 and armv7s, and still I get this error.
我选择只为 armv7 和 armv7s 构建,但仍然出现此错误。
I do not understand why this will not build.
我不明白为什么这不会建立。
采纳答案by deltheil
I have chosen to only build for armv7 and armv7s, and still i get this error.
我选择只为 armv7 和 armv7s 构建,但仍然出现此错误。
Have you looked at the Xcode build logs to confirm that only -arch armv7
and -arch armv7s
are used for compilation?
你看Xcode的构建日志,确认只有-arch armv7
和-arch armv7s
用于编译?
Your problem is certainly related to the fact that you use a single set of headers (e.g generated for a 32-bit build of the library) even though you try to build a fat executable that combines armv7/v7s and arm64 architectures.
您的问题肯定与您使用一组标头(例如,为库的 32 位构建生成)这一事实有关,即使您尝试构建结合 armv7/v7s 和 arm64 体系结构的胖可执行文件。
I think you should refer to Nick Zitzmann libcurl pre-built. As you can see the curlbuild.h
header that ships with it includes ad-hoc macros to distinguish between ILP32 and LP64:
我认为您应该参考Nick Zitzmann libcurl pre-built。如您所见curlbuild.h
,随附的标头包含用于区分 ILP32 和 LP64 的专用宏:
/* The size of `long', as computed by sizeof. */
#ifdef __LP64__
#define CURL_SIZEOF_LONG 8
#else
#define CURL_SIZEOF_LONG 4
#endif
Note that the instructions on Nick's page do not include any precision about how this header has been generated - I would say it has been modified specifically to be cross-platform compliant.
请注意,Nick 页面上的说明不包括有关如何生成此标头的任何精确性 - 我想说它已被专门修改为跨平台兼容。
UPDATE
更新
The above link is down (one can find a snapshot on the Internet Archive- the latest pre-built was made for libcurl 7.40.0 from 2015-01-08). I made a copy (verbatim) of build-libcurl-ios.sh
and curlbuild.h
(the single, convenient header made for the iOScURL
application) here.
上面的链接已关闭(可以在Internet Archive上找到快照- 最新的预构建是从 2015 年 1 月 8 日开始为 libcurl 7.40.0 制作的)。我做了一个副本(逐字)build-libcurl-ios.sh
和curlbuild.h
(用于制作单,头方便iOScURL
应用程序)在这里。
After the armv7
build the build-libcurl-ios.sh
makes a copy of the generated 32-bit header:
后armv7
生成的build-libcurl-ios.sh
,使所生成的32位的报头的副本:
cp include/curl/curlbuild.h ~/Desktop/curlbuild32.h
Same thing after the arm64
build:
arm64
构建后同样的事情:
cp include/curl/curlbuild.h ~/Desktop/curlbuild64.h
The final curlbuild.h
is no more than a convenient version that includes both 32-bit and 64-bit specifics thanks to #ifdef __LP64__ /* ... */ #else /* ... */ #endif
sections. In particular there is more than only CURL_SIZEOF_LONG
differences, e.g.:
由于部分的原因,最终curlbuild.h
版本只不过是一个方便的版本,包括 32 位和 64 位的细节#ifdef __LP64__ /* ... */ #else /* ... */ #endif
。特别是有更多的CURL_SIZEOF_LONG
差异,例如:
#define CURL_TYPEOF_CURL_OFF_T int64_t /* 64-bit */
#define CURL_TYPEOF_CURL_OFF_T long /* 32-bit */
回答by arrtchiu
I didn't want to go through each of the differences between the 32-bit and 64-bit headers, so instead did this:
我不想详细介绍 32 位和 64 位标头之间的每个差异,所以改为这样做:
- Made 32 and 64-bit builds of libcurl including headers, using the script found here: http://feedback.datalogics.com/knowledgebase/articles/821196-building-openssl-and-curl-for-ios-64-bit-platform
- Put the headers into
include-32
andinclude-64
directories. - Set header search-paths to include a directory above the directories created in step 2.
Created a header file called
my_curl.h
like so:#ifdef __LP64__ #include <include-64/curl/curl.h> #else #include <include-32/curl/curl.h> #endif
- 使用此处找到的脚本制作 32 位和 64 位 libcurl 版本,包括标头:http: //feedback.datalogics.com/knowledgebase/articles/821196-building-openssl-and-curl-for-ios-64-bit-平台
- 将标题放入
include-32
和include-64
目录中。 - 设置标题搜索路径以在步骤 2 中创建的目录上方包含一个目录。
创建了一个
my_curl.h
像这样调用的头文件:#ifdef __LP64__ #include <include-64/curl/curl.h> #else #include <include-32/curl/curl.h> #endif
Perhaps not the most elegant solution, but it saved me the time (and risk of mistakes) of doing it by hand.
也许不是最优雅的解决方案,但它为我节省了手动完成的时间(和出错的风险)。