10

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.

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.

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:

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 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.

I have chosen to only build for armv7 and armv7s, and still I get this error.

I do not understand why this will not build.

2 Answers 2

8

I have chosen to only build for armv7 and armv7s, and still i get this error.

Have you looked at the Xcode build logs to confirm that only -arch armv7 and -arch armv7s are used for compilation?

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.

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:

/* 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.

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.

After the armv7 build the build-libcurl-ios.sh makes a copy of the generated 32-bit header:

cp include/curl/curlbuild.h ~/Desktop/curlbuild32.h

Same thing after the arm64 build:

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.:

#define CURL_TYPEOF_CURL_OFF_T int64_t /* 64-bit */
#define CURL_TYPEOF_CURL_OFF_T long    /* 32-bit */
Sign up to request clarification or add additional context in comments.

1 Comment

With the above modification to the curlbuild.h header file, using Xcode 5.1, I can now build on iOS for all architectures. It does not explain why the previous version of Xcode was building for arm64 when I specifically excluded that from my settings, but since all architectures build and work now, I can move on...
0

I didn't want to go through each of the differences between the 32-bit and 64-bit headers, so instead did this:

  1. 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
  2. Put the headers into include-32 and include-64 directories.
  3. Set header search-paths to include a directory above the directories created in step 2.
  4. 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
    

Perhaps not the most elegant solution, but it saved me the time (and risk of mistakes) of doing it by hand.

2 Comments

Hey @arrtchiu I wanted to try your approach but the link u posted is broken. Do u know where i can find that script u used?
Sorry for delayed reply. I eventually stopped using this approach in favour of a more integrated solution called hunter ( github.com/ruslo/hunter ) which took care of it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.