[CDRIVER-1191] Windows build error compiling libbson Created: 01/Apr/16  Updated: 26/Oct/20  Resolved: 04/Apr/16

Status: Closed
Project: C Driver
Component/s: libbson
Affects Version/s: 1.4.0
Fix Version/s: 1.4.0

Type: Bug Priority: Major - P3
Reporter: Jeremy Mikola Assignee: Hannes Magnusson
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to PHPC-629 Upgrade libbson and libmongoc to 1.4.0 Closed
is related to CDRIVER-1145 Implement Decimal 128 type spec Closed
is related to CDRIVER-2245 Macro redefinition of printf integer ... Closed

 Description   

Spotted a few build errors (and warnings) while compiling 1.4.0 in VS2015 x86 for PHPC-629. It's possible the MONGOC_ENABLE_SASL redefinition warning is my fault (due to an AC_DEFINE() in config.w32), but the other errors appear to be internal:

c:\php-sdk\phpdev\vc14\x86\pecl\mongodb\src\libbson\src\bson\bson-compat.h(110):
 warning C4005: 'PRIi32': macro redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.h(130)
: note: see previous definition of 'PRIi32'
c:\php-sdk\phpdev\vc14\x86\pecl\mongodb\src\libbson\src\bson\bson-compat.h(113):
 warning C4005: 'PRIi64': macro redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.h(131)
: note: see previous definition of 'PRIi64'
c:\php-sdk\phpdev\vc14\x86\pecl\mongodb\src\libbson\src\bson\bson-compat.h(114):
 warning C4005: 'PRId64': macro redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.h(112)
: note: see previous definition of 'PRId64'
c:\php-sdk\phpdev\vc14\x86\pecl\mongodb\src\libbson\src\bson\bson-compat.h(115):
 warning C4005: 'PRIu64': macro redefinition
C:\Program Files (x86)\Windows Kits\10\include\10.0.10240.0\ucrt\inttypes.h(169)
: note: see previous definition of 'PRIu64'
c:\php-sdk\phpdev\vc14\x86\pecl\mongodb\src\libbson\src\bson\bson-decimal128.h(6
2): error C2054: expected '(' to follow '_Decimal128'
c:\php-sdk\phpdev\vc14\x86\pecl\mongodb\src\libbson\src\bson\bson-decimal128.h(6
3): error C2085: 'bson_decimal128_to_Decimal128': not in formal parameter list
c:\php-sdk\phpdev\vc14\x86\pecl\mongodb\src\libbson\src\bson\bson-decimal128.h(6
3): error C2143: syntax error: missing ';' before '{'
c:\php-sdk\phpdev\vc14\x86\pecl\mongodb\src\libbson\src\bson\bson-decimal128.h(7
1): error C2146: syntax error: missing ')' before identifier 'decimal128'
c:\php-sdk\phpdev\vc14\x86\pecl\mongodb\src\libbson\src\bson\bson-decimal128.h(7
1): error C2061: syntax error: identifier 'decimal128'
c:\php-sdk\phpdev\vc14\x86\pecl\mongodb\src\libbson\src\bson\bson-decimal128.h(7
1): error C2059: syntax error: ';'
c:\php-sdk\phpdev\vc14\x86\pecl\mongodb\src\libbson\src\bson\bson-decimal128.h(7
1): error C2059: syntax error: ','
c:\php-sdk\phpdev\vc14\x86\pecl\mongodb\src\libbson\src\bson\bson-decimal128.h(7
2): error C2059: syntax error: ')'
c:\php-sdk\phpdev\vc14\x86\pecl\mongodb\src\libmongoc\src\mongoc\mongoc-config.h
(37): warning C4005: 'MONGOC_ENABLE_SASL': macro redefinition
c:\php-sdk\phpdev\vc14\x86\php-7.0.2-src\main\config.w32.h(272): note: see previ
ous definition of 'MONGOC_ENABLE_SASL'



 Comments   
Comment by Scott Willis [ 26/Oct/20 ]

This issue (still) occurs when bson.h is #included before inttypes.h:

  1. bson.h #includes bson-compat.h, which defines constants duplicating those in inttypes.h, including:
    1. PRIi32
      PRId32
      PRIu32
      PRIi64
      PRId64
      PRIu64
  2. These definitions are currently protected by e.g. #ifndef PRIi32  (added in CDRIVER-2245).  This will prevent issues if inttypes.h is #included before bson.h.
  3. However, if bson.h is #included before inttypes.h then the constants will not yet have been defined when the conditionals are evaluated, so bson-compat.h will define them.  Then inttypes.h (if used) will redefine them.
Comment by Hannes Magnusson [ 04/Apr/16 ]

Closing as works as designed.

You probably did something weird while configuring libbson.
Please make clean, and rerun the configure step and try again

Comment by Hannes Magnusson [ 01/Apr/16 ]

c:\php-sdk\phpdev\vc14\x86\pecl\mongodb\src\libbson\src\bson\bson-decimal128.h(62): error C2054: expected '(' to follow '_Decimal128'

Line#62 is inside an

#ifdef BSON_HAVE_DECIMAL128

https://github.com/mongodb/libbson/blob/master/src/bson/bson-decimal128.h#L60

Can you check your code again?

Comment by Jeremy Mikola [ 01/Apr/16 ]

PHP's aclocal.m4 and acinclude.m4 (presumably from phpize) both end up including the following snippet:

#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif

I see no other references to "inttypes.h" in the driver sources.

Our config.w32 file is also disabling decimal 128 on Windows:

AC_DEFINE("BSON_HAVE_DECIMAL128", 0);

Comment by Hannes Magnusson [ 01/Apr/16 ]

Windows doesn't have _Decimal128.

Where how/did you include inttypes.h? We either include inttypes or define the macros, not both.

Generated at Wed Feb 07 21:11:50 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.