Re: Understanding Xcode build errors from using Objective-C runtime function in OS X's Foundation app template.

  • I'm learning how to use the Objective-C runtime function. To do this, I used Xcode Version 4.6.2 (4H1003) and chose from the OS X's Foundation template to create a new project with sample code I found in Apple's documentation.

    There are only three files in the project.

    main.m

    #import <Foundation/Foundation.h>
    #include "ObjectiveCRuntime.h"

    int main(int argc, const char * argv[])
    {
        @autoreleasepool {
            listObjectiveC_ClassesUsedInThisApp();
        }
        return 0;
    }

    ObjectiveCRuntime.h

    #ifndef ObjCWithoutCocoa_ObjectiveCRuntime_h
    #define ObjCWithoutCocoa_ObjectiveCRuntime_h

    void listObjectiveC_ClassesUsedInThisApp(void); /* list Objective-C classes used by this executable */

    #endif

    and ObjectiveCRuntime.c

    #import <Foundation/Foundation.h>
    #import <Foundation/NSObjCRuntime.h>
    #import "ObjectiveCRuntime.h"

    extern int objc_getClassList(Class *buffer, int bufferLen);

    /* list Objective-C classes used by this executable */
    void listObjectiveC_ClassesUsedInThisApp(void)
    {
        int numClasses;
        Class * classes = NULL;

        classes = NULL;
        numClasses = objc_getClassList(NULL, 0);

        if (numClasses > 0 )
        {
            classes = malloc(sizeof(Class) * numClasses);
            numClasses = objc_getClassList(classes, numClasses);
            printf("This application has %u classes. Note that you cannot assume these classes inherit from NSObject.\n", numClasses);
            free(classes);
        }
    }

    When I build, Xcode emits build fail errors
    <XcodeScreenSnapz001.jpeg>

    Since Apple provided headers shouldn't be the source of errors, I'm not sure where to start looking for the error. The ObjectiveCRuntime.c and main.m are listed in the Target's Build Phases under Compile Sources.

    Thanks for any hints.
  • On May 29, 2013, at 9:32 PM, Chris in Public <mailbox20040630...> wrote:

    > When I build, Xcode emits build fail errors
    > <XcodeScreenSnapz001.jpeg>

    The screenshot didn’t come through. But you should paste the errors as text instead, anyway; the mailing list tends not to allow attachments. Go to the build results tab in Xcode, then you can copy the text of the errors.

    > extern int objc_getClassList(Class *buffer, int bufferLen);

    You shouldn’t put in your own declarations of system functions. The point of including the system headers is so you get the official declarations. This one’s either going to be redundant, or if it’s different the compiler will complain.

    > printf("This application has %u classes. Note that you cannot assume these classes inherit from NSObject.\n", numClasses);

    numClasses is declared as an int, not unsigned, so the format specifier should be %d, not %u. This might be giving you an error.

    —Jens
  • On May 30, 2013, at 12:48 AM, Jens Alfke wrote:

    >
    > On May 29, 2013, at 9:32 PM, Chris in Public <mailbox20040630...> wrote:
    >
    >> When I build, Xcode emits build fail errors
    >> <XcodeScreenSnapz001.jpeg>
    >
    > The screenshot didn’t come through. But you should paste the errors as text instead, anyway; the mailing list tends not to allow attachments. Go to the build results tab in Xcode, then you can copy the text of the errors.

    If you're going to post screenshots, it's pretty easy (and free) to use http://Imgur.com to host them.  Also, it's less bandwidth emailing photos around to everyone.

    Here's a sample:
    http://i.imgur.com/3oX9c.png
previous month may 2013 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