[SERVER-20320] use of undeclared identifier 'drem' Created: 09/Sep/15  Updated: 18/Aug/16  Resolved: 26/Jan/16

Status: Closed
Project: Core Server
Component/s: Build
Affects Version/s: 3.0.6
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Ryan Schmidt Assignee: Andrew Morrow (Inactive)
Resolution: Incomplete Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible
Operating System: ALL
Sprint: Build 9 (09/18/15), Build A (10/09/15), Build B (10/30/15), Build C (11/20/15), Build D (12/11/15), Platforms F (01/29/16)
Participants:

 Description   

Hello, I'm trying to build mongodb 3.0.6 (plus this patch) on OS X 10.7 Lion. I'm using --c++11, --libc++, and a suitably new clang compiler from MacPorts. The error I get is:

src/third_party/s2/s1angle.cc:28:14: error: use of undeclared identifier 'drem'
  radians_ = drem(radians_, 2.0 * M_PI);
             ^
1 error generated.
scons: *** [build/darwin/64/c++11_on/cc__Volumes_Data_macports_lion_bin_clang-mp-3.4/cxx__Volumes_Data_macports_lion_bin_clang++-mp-3.4/libc++/osx-version-min_10.7/ssl/third_party/s2/s1angle.o] Error 1
scons: building terminated because of errors.
Command failed:  cd "/Volumes/Data/macports/lion/var/macports/build/_Volumes_Data_macports_dports_databases_mongodb/mongodb/work/mongodb-src-r3.0.6" && /Volumes/Data/macports/lion/bin/scons all mongobridge mongosniff --cc=/Volumes/Data/macports/lion/bin/clang-mp-3.4 --cxx=/Volumes/Data/macports/lion/bin/clang++-mp-3.4 --c++11 --cpppath=/Volumes/Data/macports/lion/include --disable-warnings-as-errors --libc++ --libpath=/Volumes/Data/macports/lion/lib --osx-version-min=10.7 --ssl --64 
Exit code: 2

drem is defined in src/third_party/s2/util/math/exactfloat/exactfloat.h. Maybe a #include is missing?



 Comments   
Comment by Ryan Schmidt [ 18/Aug/16 ]

If there is a problem with my toolchain, then it's a problem Apple shipped to all users of 10.7, which will not be fixed, because 10.7 receives no further updates.

It looks like math.h received an overhaul between 10.7 and 10.8. There may have been a bug in the 10.7 version of math.h that prevents drem from being defined, though it would be surprising that that was not noticed and fixed during the time 10.7 received updates. Or there may be a specific combination of defines that need to be set to enable it.

Fortunately Apple does bundle its OS headers and libraries into "SDKs" which are included with Xcode. Xcode 4.4 through 4.6.3 for 10.7 include the 10.8 SDK, so it's possible to build mongodb on 10.7 using the 10.8 SDK and its working math.h, by adding -isysroot/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk to CCFLAGS and adding -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk to LINKFLAGS. I've done this in MacPorts (https://trac.macports.org/changeset/151595) and MacPorts users running 10.7 can now once again install mongodb.

Even as far back as 10.6 (and I did not check earlier versions), drem and related functions are listed as "legacy BSD functions", to be avoided in favor of their modern C99 counterparts; in the case of drem, remainder is the suggested alternative. I haven't yet tried simply replacing all occurrences of "drem" with "remainder"; I don't know if that would work correctly, but you may want to look into that, unless you still need to support other even older platforms that don't have remainder.

Comment by Andrew Morrow (Inactive) [ 26/Jan/16 ]

Hi ryandesign - At this time we don't have any further recommendation. We are able to successfully build the MongoDB 3.0 branch with XCode 5.1.1 plus when targeting OS X 10.7 with the system libc++. Please see here for logs:

https://evergreen.mongodb.com/task_log_raw/mongodb_mongo_v3.0_osx_108_compile_20d60d3491908f1ae252fe452300de3978a040c7_16_01_20_21_40_20/0?type=T

While we suspect a problem with your toolchain, we aren't 100% sure. However, given the old age of the target platform, and the widespread adoption of newer OS X versions, and your success building on OS X 10.8, we don't feel that this ticket warrants further investigation.

If you are able to discover a root cause we are happy to re-open and work on a fix, but constructing the necessary clean-room environments to do the root cause analysis is not something we believe to be warranted.

Comment by Ryan Schmidt [ 30/Nov/15 ]

Now I am the one who must apologize for the delay. I was having trouble finding time to set up some new OS X test machines. But it's done now.

The good news is that mongodb 3.0.7 in MacPorts builds fine on OS X 10.8, forcing the use of libc++. The bad news is that it still fails on a newly set up OS X 10.7 machine, with the error originally described: error: use of undeclared identifier 'drem'. It's the same with clang 3.4.2 and clang 3.7.0, both installed by MacPorts.

Comment by Ramon Fernandez Marina [ 11/Nov/15 ]

Apologies for the radio silence here ryandesign. Is this still an issue for you? Since test.c compiles other programs using the drem() function should too – or are you still having trouble compiling 3.0.6?

Thanks,
Ramón.

Comment by Ryan Schmidt [ 22/Sep/15 ]

It all seems to work:

$ clang-mp-3.4 -o test test.c
$ otool -L test
test:
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
$ ./test
1.000000

$ clang++-mp-3.4 -o test-libstdc++ test.cpp
$ otool -L test-libstdc++
test-libstdc++:
	/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 52.0.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
$ ./test-libstdc++
1.000000

$ clang++-mp-3.4 -stdlib=libc++ -o test-libc++ test.cpp
$ otool -L test-libc++
test-libc++:
	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 28.4.0)
	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
$ ./test-libc++
1.000000

Comment by Jonathan Reams [ 22/Sep/15 ]

Ryan, can you try compiling this test program with your macports clang? It shouldn't require any flags, just clang -o test test.c. The drem function is part of the standard C library, so if your compiler can't find it, that would suggest that the compiler has issues.

#include <stdio.h>
#include <math.h>
 
int main() {
        double a = 1.0, b = 2.0, r;
        r = drem(a, b);
        printf("%f\n", r);
        return 0;
}

Comment by Ryan Schmidt [ 21/Sep/15 ]

Ah, the different problem with 3.0.4 was SERVER-13829. After specifying a shorter variant-dir, 3.0.4 builds fine.

I should correct what I said above: Xcode 4.6.3 includes "Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)" as the default compiler, but your build system says that's too old:

Checking if C compiler is clang 3.4 (or Apple XCode 5.1.1) or newer...no
Checking if C++ compiler is clang 3.4 (or Apple XCode 5.1.1) or newer...no
ERROR: Refusing to build with compiler that does not meet requirements

So instead we use "clang version 3.4.2 (tags/RELEASE_34/dot2-final)" installed with MacPorts. That built 3.0.4 successfully (with libstdc++ and no C++11), but trying to build 3.0.6 (with libc++ and C++11) produces the error I reported. We do have even newer versions of clang in MacPorts that we could try.

Comment by Ryan Schmidt [ 21/Sep/15 ]

Nothing has changed; please re-open (if my adding this comment does not do so automatically; I don't know how your issue tracker works).

I don't know how to answer your questions. I'm using Xcode 4.6.3 and its included copy of "Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)". This is the latest Apple toolchain that is or ever will be available for OS X 10.7. I do see a /usr/include/math.h file, which hasn't changed since 2011.

I know that mongodb 2.6.6 built fine on this system. I just tried 3.0.4 again, since that's the last version that worked without C++11. I think it got past this problem, but encountered a different one; I'll file a new ticket for that.

Comment by Jonathan Reams [ 21/Sep/15 ]

ryandesign, I haven't heard back from you on this, so I'm going to close this for now. If you have any more questions or problems, feel free to re-open this.

Comment by Jonathan Reams [ 17/Sep/15 ]

ryandesign, are you still having issues with this?

Comment by Jonathan Reams [ 10/Sep/15 ]

Hi Ryan, does your compiler have a valid math.h? What's your standard include path? The undefined identifier is part of the standard C library, and our use of it hasn't changed in 3 years, so I don't think this is a change on our side.

Generated at Thu Feb 08 03:53:51 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.