[CDRIVER-1970] Conflicting symbols "MAX" and "MIN" on FreeBSD Created: 29/Dec/16  Updated: 12/Jan/17  Resolved: 05/Jan/17

Status: Closed
Project: C Driver
Component/s: libmongoc
Affects Version/s: 1.5.1
Fix Version/s: 1.5.2

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

FreeBSD 10.2-RELEASE FreeBSD 10.2-RELEASE #0 r286666: Wed Aug 12 15:26:37 UTC 2015 root@releng1.nyi.freebsd.org:/usr/obj/usr/src/sys/GENERIC amd64

FreeBSD clang version 3.4.1 (tags/RELEASE_34/dot1-final 208032) 20140512
Target: x86_64-unknown-freebsd10.2
Thread model: posix

make 20140620

PEAR Version: 1.9.4
PHP Version: 5.6.27
Zend Engine Version: 2.6.0


Attachments: Text File mbuild.txt    

 Description   

I used pecl to install 1.1.9 mongodb driver without issue.

I'm trying to upgrade to 1.2.2, but libmongoc is causing me issues.

This commit changed hardcoded defaults in mongoc-cursor.c to mongoc-cursor-private.h

https://github.com/mongodb/mongo-c-driver/commit/b14c511dbb756ecb19f2decb59f59fbe7541d863

This should work just fine, since that file is #include'd in mongoc-cursor.c, but for some reason when I try to build it, it fails with these errors:

/tmp/pear/mongodb/src/libmongoc/src/mongoc/mongoc-cursor.c:1016:32: error: use of undeclared identifier 'MAX'
      } else if (!strcmp (key, MAX)) {
                               ^
/tmp/pear/mongodb/src/libmongoc/src/mongoc/mongoc-cursor.c:1027:32: error: use of undeclared identifier 'MIN'
      } else if (!strcmp (key, MIN)) {
                               ^
/tmp/pear/mongodb/src/libmongoc/src/mongoc/mongoc-cursor.c:1354:24: error: use of undeclared identifier 'MAX'
   } else if (!strcmp (MAX, query_field)) {
                       ^
/tmp/pear/mongodb/src/libmongoc/src/mongoc/mongoc-cursor.c:1355:20: error: use of undeclared identifier 'MAX'
      *cmd_field = MAX;
                   ^
/tmp/pear/mongodb/src/libmongoc/src/mongoc/mongoc-cursor.c:1357:24: error: use of undeclared identifier 'MIN'
   } else if (!strcmp (MIN, query_field)) {
                       ^
/tmp/pear/mongodb/src/libmongoc/src/mongoc/mongoc-cursor.c:1358:20: error: use of undeclared identifier 'MIN'
      *cmd_field = MIN;
                   ^
6 errors generated.
*** Error code 1

I'm not sure if I'm using the wrong make (I tried gmake 4.2.1 but no change) or the wrong cc (I tried gcc 4.8.5 but no change), or if there is some other issue going on.

Here's the output of the build – ignore the extra -L CFLAGS definition, was just trying shotgun ideas, to no avail. I've attached as a text file.

downloading mongodb-1.2.2.tar ...
Starting to download mongodb-1.2.2.tar (4,976,128 bytes)
...........................................done: 4,976,128 bytes
400 source files, building
running: phpize
Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226
building in /tmp/pear/pear-build-rootsplUam/mongodb-1.2.2
running: /tmp/pear/mongodb/configure
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking for cc... cc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether cc accepts -g... yes
checking for cc option to accept ISO C89... none needed
checking how to run the C preprocessor... cc -E
checking for icc... no
checking for suncc... no
checking whether cc understands -c and -o together... yes
checking for system library directory... lib
checking if compiler supports -R... no
checking if compiler supports -Wl,-rpath,... yes
checking build system type... amd64-unknown-freebsd10.2
checking host system type... amd64-unknown-freebsd10.2
checking target system type... amd64-unknown-freebsd10.2
checking for PHP prefix... /usr/local
checking for PHP includes... -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib
checking for PHP extension directory... /usr/local/lib/php/20131226
checking for PHP installed headers prefix... /usr/local/include/php
checking if debug is enabled... no
checking if zts is enabled... no
checking for re2c... no
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
checking for gawk... no
checking for nawk... nawk
checking if nawk is broken... no
checking whether to enable mongodb support... yes, shared
checking OpenSSL dir for mongodb... yes
checking whether to use system default cipher list instead of hardcoded value... no
checking PHP version... 50627
checking whether to enable developer build flags... no
checking whether to enable code coverage... no
checking whether to use system libbson... no
checking configuring libmongoc... ...
checking whether to use system libmongoc... no
checking for pkg-config... /usr/local/bin/pkg-config
checking for pcre-dir install prefix... yes, shared
checking for pcre... found in /usr/local
checking for Cyrus SASL support... auto
checking for SASL... found in /usr/local
checking for sasl_version in -lsasl2... yes
checking for sasl_client_done in -lsasl2... yes
checking if weak symbols are supported... yes
checking if compiler needs -Werror to reject unknown flags... no
checking for the pthreads library -lpthreads... no
checking whether pthreads work without any flags... no
checking whether pthreads work with -Kthread... no
checking whether pthreads work with -kthread... no
checking for the pthreads library -llthread... no
checking whether pthreads work with -pthread... yes
checking for joinable pthread attribute... PTHREAD_CREATE_JOINABLE
checking if more special flags are required for pthreads... -D_THREAD_SAFE
checking for PTHREAD_PRIO_INHERIT... yes
checking for shm_open... yes
checking for __sync_add_and_fetch_4... yes
checking for __sync_add_and_fetch_8... yes
checking for strnlen... yes
checking for reallocf... yes
checking for syscall... yes
checking for SYS_gettid... no
checking for snprintf... yes
checking for _set_output_format... no
checking for struct timespec... yes
checking for library containing clock_gettime... none required
checking for pthread_join in LIBS= with CFLAGS=-D_THREAD_SAFE -pthread... yes
checking if compiler needs -Werror to reject unknown flags... no
checking for joinable pthread attribute... PTHREAD_CREATE_JOINABLE
checking if more special flags are required for pthreads... -D_THREAD_SAFE
checking for PTHREAD_PRIO_INHERIT... (cached) yes
checking whether PTHREAD_ONCE_INIT needs braces... no
checking for stdint-types....... "(putting them into /tmp/pear/mongodb/src/libbson/src/bson/bson-stdint.h)"
checking for uintptr_t... yes
checking for uint64_t... yes
... seen our uintptr_t in stdint.h (uint64_t too)
creating /tmp/pear/mongodb/src/libbson/src/bson/bson-stdint.h : __TMP_PEAR_MONGODB_SRC_LIBBSON_SRC_BSON_BSON_STDINT_H
checking for int_least32_t... yes
checking for int_fast32_t... yes
..adding include stdint.h
... seen good stdint.h inttypes
... seen good uint64_t
... DONE /tmp/pear/mongodb/src/libbson/src/bson/bson-stdint.h
checking whether byte ordering is bigendian... no
checking for ANSI C header files... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking for stdbool.h that conforms to C99... yes
checking for _Bool... yes
checking for clock_gettime... yes
checking for strnlen... yes
checking for snprintf... (cached) yes
configure: Current version (from VERSION_CURRENT file): 1.5.0
configure: creating ./config.status
config.status: creating /tmp/pear/mongodb/src/libmongoc/src/mongoc/mongoc-config.h
configure: creating ./config.status
config.status: creating /tmp/pear/mongodb/src/libmongoc/src/mongoc/mongoc-config.h
config.status: creating /tmp/pear/mongodb/src/libmongoc/src/mongoc/mongoc-version.h
configure: Current version (from VERSION_CURRENT file): 1.5.0
configure: creating ./config.status
config.status: creating /tmp/pear/mongodb/src/libmongoc/src/mongoc/mongoc-config.h
config.status: creating /tmp/pear/mongodb/src/libmongoc/src/mongoc/mongoc-version.h
config.status: creating /tmp/pear/mongodb/src/libbson/src/bson/bson-config.h
configure: creating ./config.status
config.status: creating /tmp/pear/mongodb/src/libmongoc/src/mongoc/mongoc-config.h
config.status: creating /tmp/pear/mongodb/src/libmongoc/src/mongoc/mongoc-version.h
config.status: creating /tmp/pear/mongodb/src/libbson/src/bson/bson-config.h
config.status: creating /tmp/pear/mongodb/src/libbson/src/bson/bson-version.h
checking for ld used by cc... /usr/bin/ld
checking if the linker (/usr/bin/ld) is GNU ld... yes
checking for /usr/bin/ld option to reload object files... -r
checking for BSD-compatible nm... /usr/local/bin/nm -B
checking whether ln -s works... yes
checking how to recognize dependent libraries... pass_all
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking the maximum length of command line arguments... 196608
checking command to parse /usr/local/bin/nm -B output from cc object... ok
checking for objdir... .libs
checking for ar... ar
checking for ranlib... ranlib
checking for strip... strip
checking if cc supports -fno-rtti -fno-exceptions... yes
checking for cc option to produce PIC... -fPIC
checking if cc PIC flag -fPIC works... yes
checking if cc static flag -static works... yes
checking if cc supports -c -o file.o... yes
checking whether the cc linker (/usr/bin/ld) supports shared libraries... yes
checking whether -lc should be explicitly linked in... no
checking dynamic linker characteristics... freebsd10.2 ld.so
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... no
 
creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
 
mongodb was configured with the following options:
 
Build configuration:
  CFLAGS                                           : -L/usr/local/lib -I/usr/local/include -L/usr/lib -I /usr/include
  Extra CFLAGS                                     :  -D_THREAD_SAFE -pthread
  Developers flags (slow)                          :
  Code Coverage flags (extra slow)                 :
  System mongoc                                    : no
  System libbson                                   : no
  LDFLAGS                                          :
  EXTRA_LDFLAGS                                    :
  MONGODB_SHARED_LIBADD                            : -Wl,-rpath,/usr/local/lib -L/usr/local/lib -lsasl2 -Wl,-rpath,/usr/local/lib -L/usr/local/lib  -lssl -lcrypto
 
Please submit bugreports at:
  https://jira.mongodb.org/browse/PHPC
 
 
config.status: creating /tmp/pear/mongodb/src/libmongoc/src/mongoc/mongoc-config.h
config.status: creating /tmp/pear/mongodb/src/libmongoc/src/mongoc/mongoc-version.h
config.status: creating /tmp/pear/mongodb/src/libbson/src/bson/bson-config.h
config.status: creating /tmp/pear/mongodb/src/libbson/src/bson/bson-version.h
config.status: creating config.h
running: make
/bin/sh /tmp/pear/pear-build-rootsplUam/mongodb-1.2.2/libtool --mode=compile cc    -I. -I/tmp/pear/mongodb -DPHP_ATOM_INC -I/tmp/pear/pear-build-rootsplUam/mongodb-1.2.2/include -I/tmp/pear/pear-build-rootsplUam/mongodb-1.2.2/main -I/tmp/pear/mongodb -I/usr/local/include/php -I/usr/local/include/php/main -I/usr/local/include/php/TSRM -I/usr/local/include/php/Zend -I/usr/local/include/php/ext -I/usr/local/include/php/ext/date/lib -I/usr/local/include -I/usr/local -I/tmp/pear/mongodb/src/BSON/ -I/tmp/pear/mongodb/src/MongoDB/ -I/tmp/pear/mongodb/src/MongoDB/Exception/ -I/tmp/pear/mongodb/src/contrib/ -I/tmp/pear/mongodb/src/libmongoc/src/mongoc/ -I/tmp/pear/mongodb/src/libbson/src/ -I/tmp/pear/mongodb/src/libbson/src/yajl/ -I/tmp/pear/mongodb/src/libbson/src/bson/  -L/usr/local/lib -I/usr/local/include -DBSON_COMPILATION -DMONGOC_COMPILATION -DMONGOC_TRACE -DHAVE_CONFIG_H  -L/usr/local/lib -I/usr/local/include -L/usr/lib -I /usr/include -D_THREAD_SAFE -pthread  -c /tmp/pear/mongodb/src/bson.c -o src/bson.lo



 Comments   
Comment by Hannes Magnusson [ 05/Jan/17 ]

Thanks! Merged to 1.5.2 and master

Comment by Githook User [ 05/Jan/17 ]

Author:

{u'username': u'ooglek', u'name': u'Peter Beckman', u'email': u'beckman@angryox.com'}

Message: CDRIVER-1522 CDRIVER-1970 update define constants for "find" opts to be unique
Branch: r1.5
https://github.com/mongodb/mongo-c-driver/commit/0b872895b58a249773aec5b4ace902db7d75d675

Comment by Githook User [ 05/Jan/17 ]

Author:

{u'username': u'ooglek', u'name': u'Peter Beckman', u'email': u'beckman@angryox.com'}

Message: CDRIVER-1522 CDRIVER-1970 update define constants for "find" opts to be unique
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/6dd99265127d45104bb722062e3f4058b2cf1f9a

Comment by Peter Beckman [ 02/Jan/17 ]

I've done what I suggested and modified the namespace for the defines in mongoc-cursor-private.h and tested successfully on FreeBSD.

Here's my pull request: https://github.com/mongodb/mongo-c-driver/pull/417

I hope this will help future users on *BSD!

Comment by Peter Beckman [ 29/Dec/16 ]

That solved it! Thank you Hannes, much appreciated.

I dug around a bit in the header files and couldn't see any reference to MAX or MIN alone, outside of the mongoc-cursor-private.h file. I thought maybe another #define failed to include an underscore, and I looked for any #undef that might have tried, but I didn't see it.

Wait – maybe an Ah-Ha moment. In mongoc-counters-private.h, for FreeBSD there is a separate include list:

#ifdef __linux__
# include <sched.h>
# include <sys/sysinfo.h>
#elif defined(__FreeBSD__) || \
      defined(__NetBSD__) || \
      defined(__DragonFly__) || \
      defined(__OpenBSD__)
# include <sys/types.h>
# include <sys/sysctl.h>
# include <sys/param.h>
#endif

In sys/params.h, lines 299 and 300, there's this beauty:

298 /* Macros for min/max. */
299 #define MIN(a,b) (((a)<(b))?(a):(b))
300 #define MAX(a,b) (((a)>(b))?(a):(b))

I suspect that is where the failure occurs. Probably makes sense to rename the #define lines in mongo-cursor-private.h to something less generic, maybe even prefix everything with MONGOC_MAX or similar.

Thanks for hunting this down Hannes! Or at least having the right idea about how to get around it. Here's the output from php -i after the install. Winning!

mongodb
 
mongodb support => enabled
mongodb version => 1.2.2
mongodb stability => stable
libmongoc version => 1.5.0
libbson version => 1.5.0

Comment by Hannes Magnusson [ 29/Dec/16 ]

I can't figure out how to reproduce this locally – although haven't tried FreeBSD yet.

The header is clearly included since the other defines in that file are use successfully in the lines above (such as HINT, COMMENT, ALLOW_PARTIAL_RESULTS).

All I can think of is one of the subsequent header includes include a platform header which undefines MAX and MIN.

Can you try this:

$ pecl download mongodb
$ tar zxvf mongodb-1.2.2.tgz
$ cd mongodb-1.2.2
$ vim src/libmongoc/src/mongoc-cursor.c
Move the #include "mongoc-cursor-private.h" to the end of the include list
$ phpize
$ ./configure && make
if that works, then you can install the extension by running:
$ make install

Comment by Peter Beckman [ 29/Dec/16 ]

This seems to be for 1.5.0, not 1.5.1, my bad.

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