Why won't iOS app using MKMapView compile?

  • Hi all.

    I put an MKMapView in my UI and tried to declare an IBOutlet for it,
    but compilation fails with this error, in MKGeometry.h:

    "'isinf' was not declared in this scope"

    The line it's griping about is

    UIKIT_STATIC_INLINE BOOL MKMapRectIsNull(MKMapRect rect) {
        return isinf(rect.origin.x) || isinf(rect.origin.y);
    }

    I've imported <MapKit/MapKit.h> where I declare the MKMapView, and
    included MapKit.framework in the project.

    Anybody know what could be wrong?  Thanks!

    Gavin
  • On 8 Jul 2011, at 13:39, G S wrote:

    > Hi all.
    >
    > I put an MKMapView in my UI and tried to declare an IBOutlet for it,
    > but compilation fails with this error, in MKGeometry.h:
    >
    > "'isinf' was not declared in this scope"
    >
    > The line it's griping about is
    >
    > UIKIT_STATIC_INLINE BOOL MKMapRectIsNull(MKMapRect rect) {
    > return isinf(rect.origin.x) || isinf(rect.origin.y);
    > }
    >
    > I've imported <MapKit/MapKit.h> where I declare the MKMapView, and
    > included MapKit.framework in the project.
    >
    > Anybody know what could be wrong?  Thanks!

    The man page for "isinf" says you will need to #include <math.h> and link with -lm.

    Chris
  • > The man page for "isinf" says you will need to #include <math.h> and link with -lm.

    Thanks, but this is in Apple's code (MKGeometry.h).  If I right-click
    on isinf in the flagged line and jump to the definition, it finds it
    in math.h.
  • This is ridiculous.  The whole project is at a standstill because of
    this nonsense.
  • -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    On 7/8/11 1:45 PM, G S wrote:
    > This is ridiculous.  The whole project is at a standstill because of
    > this nonsense.

    Just breathe...

    I have used MKMapView just as you described: add the framework, import
    the header, go.  It works.

    It seems likely that there is something amiss in your situation.  This
    doesn't mean it's YOUR fault, merely that it's probably NOT the
    framework's fault.

    I guess I'd start by trying the following:

    1) If you haven't already done so, do a clean build (including dumping
    any precompiled headers).  I don't know why, but I've seen this fix all
    sorts of strange problems.

    2) If that doesn't work, try building a MapKit sample code project.

    3) If #2 succeeds, then it must be your code (or, less likely, something
    in your build settings) and we would need to see more to understand.

    4) If #2 fails, your development environment is probably damaged in some
    way and you might need to do an Xcode reinstall.

    This is all pretty generic absent more information...

    - --
    Conrad Shultz

    Synthetiq Solutions
    www.synthetiqsolutions.com
    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.4.7 (Darwin)
    Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

    iD8DBQFOF2/CaOlrz5+0JdURAkP1AJ9uqdaNkHSs2BdA5hBRIsylpGnqKQCaApHG
    A9KwsPWxODnJSi4yVc4MKK0=AgcW
    -----END PGP SIGNATURE-----
  • I think you need to #include <math.h>  to get the isinf macro.

    On Jul 8, 2011, at 2:45 PM, G S wrote:

    > This is ridiculous.  The whole project is at a standstill because of
    > this nonsense.
    >
  • On 07/08/2011 5:39 AM, "G S" <stokestack...> wrote:

    > I've imported <MapKit/MapKit.h>  where I declare the MKMapView...

    Do you mean this literally?  If you put an import within an interface's
    variables section, I'd be surprised you don't find lots of other errors.

    Try showing your exact code.
  • On Fri, Jul 8, 2011 at 1:45 PM, G S <stokestack...> wrote:
    > This is ridiculous.  The whole project is at a standstill because of
    > this nonsense.

    Since nobody else is appearing to have this problem, you might do best
    to whittle down your configuration into the smallest possible case
    that reproduces the bug.

    But my gut says that something that's getting included before
    MKMapKit.h is at fault. Maybe a missing semicolon in another include
    file?

    --Kyle Sluder
  • As the OP noted, the error is in MapKit code and it is thus MapKit's responsibility to include requisite headers.

    There is some more fundamental problem at play.

    (Sent from my iPhone.)

    --
    Conrad Shultz
    www.synthetiqsolutions.com

    On Jul 8, 2011, at 14:30, koko <koko...> wrote:

    > I think you need to #include <math.h>  to get the isinf macro.
  • On Fri, Jul 8, 2011 at 4:00 PM, Conrad Shultz
    <conrad...> wrote:
    > As the OP noted, the error is in MapKit code and it is thus MapKit's responsibility to include requisite headers.
    >
    > There is some more fundamental problem at play.

    Well, CoreFoundation.h includes <math.h> according to my copy of the
    4.2 SDK, and isinf is defined in both the simulator's and the device's
    math.h.

    CoreFoundation.h is #imported by Foundation.h. Gavin, have you somehow
    omitted Foundation.h from your prefix header (or whatever code is
    #importing MapKit.h)?

    --Kyle Sluder
  • First of all, thanks a lot for the responses.

    I have compiled a couple of examples, and they do build. That makes
    this all the more perplexing. The MapCallouts tutorial is one that I
    tried.
    In their file that uses MKMapView, these are the import statements:

    #import <UIKit/UIKit.h>
    #import <MapKit/MapKit.h>

    Now the import statements in my file that uses MKMapView:

    #import <UIKit/UIKit.h>
    #import <MapKit/MapKit.h>

    Yep, identical.

    Now let's take a look at the included frameworks:

    http://farm7.static.flickr.com/6136/5917058068_14504106f4_z.jpg

    I link in everything they do.

    I refer to math.h in one file in my project (which works, and is not
    included in the problematic file).  If I comment out that inclusion,
    compilation still fails with the same complaint.

    I've tried removing and re-adding the frameworks to the project (most
    of us have probably seen this fix things before).  I cleaned the
    project and restarted Xcode.  Still no dice.

    Harumph.
  • On 07/08/2011 4:27 PM, "G S" <stokestack...> wrote:

    > First of all, thanks a lot for the responses.
    > I have...
    > Yep, identical.
    > Now let's ...
    > I link in everything they do.
    > I refer to math.h ...
    > I've tried ...  Still no dice.

    I've occasionally seen problems similar to this where the only recourse
    was either a new Xcode project from scratch, a low-level editing of the
    project file itself, or a restore from an earlier version and re-addition
    of later changes.
  • On Jul 8, 2011, at 4:27 PM, G S wrote:

    > First of all, thanks a lot for the responses.
    >
    > I have compiled a couple of examples, and they do build. That makes
    > this all the more perplexing. The MapCallouts tutorial is one that I
    > tried.
    > In their file that uses MKMapView, these are the import statements:
    >
    > #import <UIKit/UIKit.h>
    > #import <MapKit/MapKit.h>
    >
    > Now the import statements in my file that uses MKMapView:
    >
    > #import <UIKit/UIKit.h>
    > #import <MapKit/MapKit.h>
    >
    > Yep, identical.
    >
    > Now let's take a look at the included frameworks:
    >
    > http://farm7.static.flickr.com/6136/5917058068_14504106f4_z.jpg
    >
    > I link in everything they do.
    >
    > I refer to math.h in one file in my project (which works, and is not
    > included in the problematic file).  If I comment out that inclusion,
    > compilation still fails with the same complaint.
    >
    > I've tried removing and re-adding the frameworks to the project (most
    > of us have probably seen this fix things before).  I cleaned the
    > project and restarted Xcode.  Still no dice.
    >
    > Harumph.

    Try #import <math.h> as the very first thing in your file.

    Try disabling precompiled headers.

    Try preprocessing your file and the example file and look for differences.

    Check the deployment target of your project and the example project; MKGeometry's inline function will be ifdef'ed out depending on the deployment target.

    --
    Greg Parker    <gparker...>    Runtime Wrangler
  • A search reveals that there are 29 math.h files on my system.  Of
    those, these don't clearly include isinf:

    /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/include/c++/4.2.1/tr1
    /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.0.sdk/usr/include/c++
    /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.1.sdk/usr/include/c++/4.2.1/tr1/4.2.1/tr1
    /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk/usr/include/c++/4.2.1/tr1
    /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/usr/include/c++/4.2.1/tr1
    /Developer/SDKs/MacOSX10.6.sdk/usr/include/c++/4.2.1/tr1
    /Developer/SDKs/MacOSX10.6.sdk/usr/include/wx-2.8/wx
    /usr/include/c++/4.2.1/tr1
    /usr/include/wx-2.8/wx

    So I tried: echo $PATH
    /usr/local/boost:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin

    Nothing obvious there.  My project's header search paths include:
    /usr/local/include

    but the only thing under there is Boost, and it doesn't have a math.h.

    No idea at this point.
  • On Fri, Jul 8, 2011 at 5:30 PM, G S <stokestack...> wrote:
    > A search reveals that there are 29 math.h files on my system.  Of
    > those, these don't clearly include isinf:
    >
    > /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/include/c++/4.2.1/tr1
    > /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.0.sdk/usr/include/c++
    > /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.1.sdk/usr/include/c++/4.2.1/tr1/4.2.1/tr1
    > /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.2.sdk/usr/include/c++/4.2.1/tr1
    > /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/usr/include/c++/4.2.1/tr1
    > /Developer/SDKs/MacOSX10.6.sdk/usr/include/c++/4.2.1/tr1
    > /Developer/SDKs/MacOSX10.6.sdk/usr/include/wx-2.8/wx
    > /usr/include/c++/4.2.1/tr1
    > /usr/include/wx-2.8/wx

    Are you compiling this file as Objective-C++?

    --Kyle Sluder
  • > Are you compiling this file as Objective-C++?

    Yes, the implementation is an mm file.
  • On Fri, Jul 8, 2011 at 5:45 PM, G S <stokestack...> wrote:
    >> Are you compiling this file as Objective-C++?
    >
    > Yes, the implementation is an mm file.
    >

    Okay, that's important.

    Look at $SDKROOT/usr/include/c++/4.2.1/cmath and you'll see that it
    #undefines isinf and declares std::isinf as a wrapper. So if you
    happen to #include <cmath> before #importing
    <MapKit/MapKitGeometry.h>, the compiler will dutifully complain.

    I don't know what the recommended solution would be here, since I
    don't work with C++. Possible solutions that come to mind are
    splitting your C++ code and Objective-C code into separate files, and
    only including the bare minimum of glue in an Objective-C++ file; or
    #importing <math.h> after whatever it is that #includes <cmath>, but
    before #importing <MapKit/MapKit.h>; or inserting a `using namespace
    std;` before #importing <MapKit/MapKit.h>.

    But it's clear this is a result of using Objective-C++, not a fault in MapKit.

    --Kyle Sluder
  • On Jul 8, 2011, at 5:51 PM, Kyle Sluder wrote:
    > But it's clear this is a result of using Objective-C++, not a fault in MapKit.

    You should file a bug report anyway, because MapKit's headers should be compatible with Objective-C++.

    --
    Greg Parker    <gparker...>    Runtime Wrangler
  • Thanks very much for that analysis, Kyle.

    This blows. All of our business logic is written in C++, which I'd
    think is a common scenario (the paucity of "business" logic in the app
    store notwithstanding). This problem is occurring in a UI controller
    that needs to show information from a C++ object. It's full of code to
    exchange information between the screen and object and validate it, so
    writing some hokey workaround using an intermediary is pretty
    unpalatable.

    Weird that explicitly importing <math.h> right before the MapKit
    import doesn't work, though.  I can't see where cmath is being
    included.  Any suggestions on tracking that down?

    Gavin
  • > You should file a bug report anyway, because MapKit's headers should be compatible with Objective-C++.

    I will.  The problem is that they're just going to bounce it back to
    me with "please provide a project that demonstrates this", and since I
    don't know where cmath is coming in, I don't know how to create a
    project to repro the problem.  I guess I'll just have to hack away at
    mine and turn that in when I have the time.

    I took the MapCallouts example project and changed its controller
    file's name extension to mm, but it still compiled.  BUT, if I put

    #import <cmath>

    at the top, BINGO.  I get the isinf error.  So Kyle's analysis was
    right on the money.

    Is there some kind of include-file-chaining analysis tool that works
    on Objective-C files? I'd think this would be one of the most useful
    programmer's tools that an IDE could offer.
  • On Jul 8, 2011, at 6:58 PM, G S wrote:
    >> You should file a bug report anyway, because MapKit's headers should be compatible with Objective-C++.
    >
    > I will.  The problem is that they're just going to bounce it back to
    > me with "please provide a project that demonstrates this", and since I
    > don't know where cmath is coming in, I don't know how to create a
    > project to repro the problem.  I guess I'll just have to hack away at
    > mine and turn that in when I have the time.
    >
    > I took the MapCallouts example project and changed its controller
    > file's name extension to mm, but it still compiled.  BUT, if I put
    >
    > #import <cmath>
    >
    > at the top, BINGO.  I get the isinf error.  So Kyle's analysis was
    > right on the money.

    Well, that sounds like a reproducing project to me.

    > Is there some kind of include-file-chaining analysis tool that works
    > on Objective-C files? I'd think this would be one of the most useful
    > programmer's tools that an IDE could offer.

    If you preprocess your source file, the output will show every include and where it came from. Not easy to interpret, but it's all there.

    --
    Greg Parker    <gparker...>    Runtime Wrangler
  • > If you preprocess your source file, the output will show every include and where it came from. Not easy to interpret, but it's all there.

    How do you do that?
  • On Fri, Jul 8, 2011 at 7:19 PM, G S <stokestack...> wrote:
    >> If you preprocess your source file, the output will show every include and where it came from. Not easy to interpret, but it's all there.
    >
    > How do you do that?

    If you're running Xcode 3, there's a Preprocess command in the menus.

    If you're running Xcode 4.0, someone at Apple decided you don't need a
    Preprocess command. So you need to copy-paste the command line from
    the Build Log and add the -E argument.

    This may or may not be the case for newer beta versions of Xcode.

    --Kyle Sluder
  • Good grief.

    Anyway, thanks for all the help and time it took.  I really appreciate it!

    For now, my workaround was to paste

    #define isinf(x)    \
    (    sizeof (x) == sizeof(float )    ?    __inline_isinff((float)(x))    \
    :    sizeof (x) == sizeof(double)    ?    __inline_isinfd((double)(x))    \
    :    __inline_isinf ((long double)(x)))

    right before the MapKit import.  It compiles now.  If my app gets
    rejected, I'll just have to point them to bug 9748279 (which I just
    filed on this issue).

    Regards,
    Gavin
previous month july 2011 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Go to today