curl-library
Re: Problem with include files - 32-bit and 64-bit modes are not supported in a "single-set of include files"
Date: Fri, 16 Sep 2016 13:40:42 +0200
On 23/11/2015 22:58, Daniel Stenberg wrote:
> (let's keep this in curl-library since it concerns the library)
>
>> During a build of curl-7.45 (and I expect earlier versions) - when
>> the target is a 32-bit build (on AIX) - sizeof(long) == 4, but on a
>> 64-bit build sizeof(long) == 8.
>
> (This has been the case since libcurl 7.19.0.)
>
> The solution people have used ever since to produce headers that can
> be used dynamically for either 32 bit or 64 bit builds is this:
>
> 1. generate a build for 32 bit, rename the curlbuild.h header
> 2. generate a build for 64 bit, rename the curlbuild.h header
> 3. make a custom small curlbuild.h version that checks if you build 32
> bit or
> 64 bit and then includes the "proper" renamed version of the generated
> header
> 4. profit!
>
Well, if all I wanted to do was build curl for personal use, that could
be okay - but I am trying to package things than depend on curl (today
that is git) - and I want to provide libraries in both 32-bit and 64-bit
mode. Again, if it was only my project(s) I could modify my include files.
> If someone has a good idea of how to tweak libcurl to make this
> process easier or more streamlined in any way, please let me know.
So, my suggestion would be to do as you suggest above - in the project.
The "complexity" may be to generate both 32-bit and 64-bit during the
configure phase.
However, rather than relying on specific ONLY - I cam up with a simple
program:
On AIX, using xlc:
root_at_x064:[/data/prj/aixtools/tests]xlc -q64 sizes.c
"sizes.c", line 3.2: 1506-948 (W) #warning __SIZEOF_LONG__ computed
"sizes.c", line 10.2: 1506-948 (W) #warning __SIZEOF_LONG_LONG__ computed
"sizes.c", line 24.3: 1506-948 (W) #warning if test 64BIT 64-bit mode
"sizes.c", line 28.3: 1506-948 (W) #warning __64BIT__ defined
root_at_x064:[/data/prj/aixtools/tests]xlc -q32 sizes.c
"sizes.c", line 3.2: 1506-948 (W) #warning __SIZEOF_LONG__ computed
"sizes.c", line 10.2: 1506-948 (W) #warning __SIZEOF_LONG_LONG__ computed
"sizes.c", line 22.3: 1506-948 (W) #warning if test 64BIT 32-bit mode
"sizes.c", line 30.3: 1506-948 (W) #warning __64BIT__ not defined
On Linux, using gcc
root_at_x066:/data/prj/aixtools/tests# gcc -m32 *.c
sizes.c:5:2: warning: #warning __SIZEOF_LONG__ is builtin [-Wcpp]
sizes.c:12:2: warning: #warning __SIZEOF_LONG_LONG__ is builtin [-Wcpp]
sizes.c:17:3: warning: #warning if test LONGS 32-bit mode [-Wcpp]
sizes.c:30:3: warning: #warning __64BIT__ not defined [-Wcpp]
sizes.c: In function ‘main’:
sizes.c:35:2: warning: incompatible implicit declaration of built-in
function ‘printf’ [enabled by default]
root_at_x066:/data/prj/aixtools/tests# gcc -m64 *.c
sizes.c:5:2: warning: #warning __SIZEOF_LONG__ is builtin [-Wcpp]
sizes.c:12:2: warning: #warning __SIZEOF_LONG_LONG__ is builtin [-Wcpp]
sizes.c:19:3: warning: #warning if test LONGS 64-bit mode [-Wcpp]
sizes.c:30:3: warning: #warning __64BIT__ not defined [-Wcpp]
sizes.c: In function ‘main’:
sizes.c:35:2: warning: incompatible implicit declaration of built-in
function ‘printf’ [enabled by default]
root_at_x066:/data/prj/aixtools/tests# cat sizes.c
#ifndef __SIZEOF_LONG__
# define __SIZEOF_LONG__ (sizeof(long))
#warning __SIZEOF_LONG__ computed
#else
#warning __SIZEOF_LONG__ is builtin
#endif
#ifndef __SIZEOF_LONG_LONG__
# define __SIZEOF_LONG_LONG__ (sizeof(long long))
#warning __SIZEOF_LONG_LONG__ computed
#else
#warning __SIZEOF_LONG_LONG__ is builtin
#endif
#ifndef _AIX
#if ( (__SIZEOF_LONG__) != (__SIZEOF_LONG_LONG__) )
# warning if test LONGS 32-bit mode
#else
# warning if test LONGS 64-bit mode
#endif
#elif ! defined(__64BIT__)
# warning if test 64BIT 32-bit mode
#else
# warning if test 64BIT 64-bit mode
#endif
#if defined(__64BIT__)
# warning __64BIT__ defined
#else
# warning __64BIT__ not defined
#endif
main()
{
printf("__SIZEOF_LONG__:%d\n", __SIZEOF_LONG__);
printf("__SIZEOF_LONG_LONG__:%d\n", __SIZEOF_LONG_LONG__);
}
++++++++
Now, I am sure a full-time programmer can come up with something better
- and still portable.
One issue with xlc is that
#if ( (__SIZEOF_LONG__) != (__SIZEOF_LONG_LONG__) )
(actually)
#if sizeof(long) != sizeof(long long)
ALWAYS returns false, as #if sizeof(xxx) always evaluates to 0 aka
FALSE. Maybe there is a way to not have __SIZEOF_LONG__ be a sizeof()
statement - rather a constant then it could be prettier.
In any case - it can be done - assuming there is an easy way to get the
configure phase to generate both "32-bit" and 64-bit" versions of
curlbuild.h
And, in short, the current setup "fails" for distribution of libcurl in
dual-bit fashion.
Michael
+++++++++
FYI:
OK - I ran a diff - to see what is actually different, some is "as
expected", but I am surprised by the different behavior re:
CURL_PULL_STDINT_H
diff -ru X32/opt/include/curl/curlbuild.h X64/opt/include/curl/curlbuild.h
--- X32/opt/include/curl/curlbuild.h 2016-09-15 07:06:04.000000000 +0000
+++ X64/opt/include/curl/curlbuild.h 2016-09-15 19:24:36.000000000 +0000
@@ -133,7 +133,7 @@
/* Configure process defines this to 1 when it finds out that system */
/* header file stdint.h must be included by the external interface. */
- #define CURL_PULL_STDINT_H 1
+ /* #undef CURL_PULL_STDINT_H */
#ifdef CURL_PULL_STDINT_H
# include <stdint.h>
#endif
@@ -140,7 +140,7 @@
/* Configure process defines this to 1 when it finds out that system */
/* header file inttypes.h must be included by the external interface. */
- #define CURL_PULL_INTTYPES_H 1
+ /* #undef CURL_PULL_INTTYPES_H */
#ifdef CURL_PULL_INTTYPES_H
# include <inttypes.h>
#endif
@@ -154,13 +154,13 @@
/* Configure process defines this to 1 when it finds out that system */
/* header file sys/poll.h must be included by the external interface. */
- #define CURL_PULL_SYS_POLL_H 1
+ /* #undef CURL_PULL_SYS_POLL_H */
#ifdef CURL_PULL_SYS_POLL_H
# include <sys/poll.h>
#endif
/* The size of `long', as computed by sizeof. */
- #define CURL_SIZEOF_LONG 4
+ #define CURL_SIZEOF_LONG 8
/* Integral data type used for curl_socklen_t. */
#define CURL_TYPEOF_CURL_SOCKLEN_T socklen_t
@@ -172,27 +172,27 @@
typedef CURL_TYPEOF_CURL_SOCKLEN_T curl_socklen_t;
/* Signed integral data type used for curl_off_t. */
- #define CURL_TYPEOF_CURL_OFF_T int64_t
+ #define CURL_TYPEOF_CURL_OFF_T long
/* Data type definition of curl_off_t. */
typedef CURL_TYPEOF_CURL_OFF_T curl_off_t;
/* curl_off_t formatting string directive without "%" conversion
specifier. */
- #define CURL_FORMAT_CURL_OFF_T "lld"
+ #define CURL_FORMAT_CURL_OFF_T "ld"
/* unsigned curl_off_t formatting string without "%" conversion
specifier. */
- #define CURL_FORMAT_CURL_OFF_TU "llu"
+ #define CURL_FORMAT_CURL_OFF_TU "lu"
/* curl_off_t formatting string directive with "%" conversion
specifier. */
- #define CURL_FORMAT_OFF_T "%lld"
+ #define CURL_FORMAT_OFF_T "%ld"
/* The size of `curl_off_t', as computed by sizeof. */
#define CURL_SIZEOF_CURL_OFF_T 8
/* curl_off_t constant suffix. */
- #define CURL_SUFFIX_CURL_OFF_T LL
+ #define CURL_SUFFIX_CURL_OFF_T L
/* unsigned curl_off_t constant suffix. */
- #define CURL_SUFFIX_CURL_OFF_TU ULL
+ #define CURL_SUFFIX_CURL_OFF_TU UL
#endif /* __CURL_CURLBUILD_H */
-------------------------------------------------------------------
List admin: https://cool.haxx.se/list/listinfo/curl-library
Etiquette: https://curl.haxx.se/mail/etiquette.html
Received on 2016-09-16