Professional Web Applications Themes

C++/Xcode - Mac Programming

Hi, I have just upgraded my computer to Panther and am converting a cocoa doent-based project from Project Builder to Xcode. Upon compilation, I get a number of errors that are due to c++ style declaration of instance variables within methods. e.g.: -(void)myMethod { int vav; vav = 2; // Lots of code int dnf; dnf = 3; } All of my files are ".m" rather than ".mm" files. So my questions are, 1) How did I get PB to compile ".m" files correctly?? Can I do the same in Xcode? I can't find any differences in the libraries or ...

  1. #1

    Default C++/Xcode

    Hi,

    I have just upgraded my computer to Panther and am converting a cocoa
    doent-based project from Project Builder to Xcode. Upon compilation, I
    get a number of errors that are due to c++ style declaration of instance
    variables within methods.

    e.g.:

    -(void)myMethod
    {
    int vav;

    vav = 2;

    // Lots of code

    int dnf;
    dnf = 3;
    }

    All of my files are ".m" rather than ".mm" files. So my questions are,

    1) How did I get PB to compile ".m" files correctly?? Can I do the same
    in Xcode? I can't find any differences in the libraries or compiler flags
    that are set in PB and Xcode.

    2) Does it make any difference in terms of compilation/execution to edit
    the files to declare the variables up front or to convert my files to
    ".mm"?? In other words, does Objective-C++ code compile and execute as
    well as Objective-C code? I am not using C++ anywhere else in the
    project.

    Thanks in advance for helping this newbie!
    Dan
    dfrank Guest

  2. #2

    Default Re: C++/Xcode

    dfrank wrote: 

    there are compiler switches you can use to force gcc to compile files in
    a certain mode, regardless of the extension. i can't remember the exact
    sequence of events, but you have to do something like define an
    EXTRA_C_FLAGS build variable (not the real name, but that's close) in a
    build style and add them in.
     

    probably! i've got xcode on my powerbook, but i don't use it to develop
    with yet. but it's surely got something similar.
     

    if it were me, i'd move all variable declarations to the top of the
    functions, kickin' it old-skule c-style. doesn't anybody remember that
    this is a *good* thing? remember how BASIC programs let you use
    variables without declaring them, and it encourages spaghetti code?

    if you're dead set on keeping variable declarations where they are, you
    can change all the extensions to .mm, or find where to put in the
    compiler switches. i use obj-c++ compilation mode on a very large
    project i'm working on, and the only drawback is that it seems to be far
    slower to compile than obj-c mode.
    Jhnny Guest

  3. #3

    Default Re: C++/Xcode

    In article <colorado.edu>, dfrank
    <edu> wrote:
     

    Someone else is going to give you a better answer but I wanted you to
    know in the meantime that you don't have to change your source files to
    force the use of the C++ compiler. I think you got PB to compile your
    ..m files by updating the compiler (I think to GCC 2.95 was when this
    came in). I am having no problems with my Objective C files (.m
    suffix) with the above code compiling just fine. I'm wondering if you
    have somehow accidentally changed the compiler settings. (I'm using
    the Compiler Default C dialect setting and it seems to work.)

    Spence

    --
    James P. Spencer
    Rochester, MN

    "Badges?? We don't need no stinkin badges!"
    James Guest

  4. #4

    Default Re: C++/Xcode

    In article <150220042259474205%net>,
    James Spencer <net> wrote:
     [/ref]

    Those are not instance variables, those are local variables. I'll take
    it you meant "c++ style declaration of local variables in the middle of
    a block" as they were introduced into C with C99?
     [/ref]

    This has something to do with the compiler version installed. Also, I
    think xCode and PB have the habit of falling back on GCC 2.95 when they
    can't find a selected compiler. So, if you explicity selected 3.1 in the
    past, and Panther replaced 3.1 with 3.2, you may suddenly be compiling
    with 2.95, which IIRC doesn't support C99-style declarations.

    I think MacOS is still lugging around GCC 2.95 for binary compatibility
    with older MacOS versions (I think Kernel extensions need to be compiled
    with 2.95, at least if they are to run on 10.0, due to some ABI change
    in 3.x).
     [/ref]

    The Objective C++ compiler takes significantly longer to compile (not
    to run, mind you) than the regular Objective C compiler. So, in the
    interest of saving precious hours of your life, I'd suggest you don't go
    the ".mm" route until you really need C++.

    Cheers,
    -- Uli
    http://www.zathras.de
    Uli Guest

  5. #5

    Default Re: C++/Xcode

    Hello,

    You just need to turn on C99 mode. I forget the exact option and I
    don't have access to my Mac right now to check, but to get to the
    setting you need to "Get Info" on your target and it is one of those
    settings.

    Michael

    edu (dfrank) wrote in message news:<colorado.edu>... 
    Michael Guest

  6. #6

    Default Re: C++/Xcode

    com (Michael Milvich) wrote in message news:<google.com>... 

    I just got home and checked, it is in the "C Language Dialect" option,
    under the Common Settings or GNU C/C++ Compiler categories.

    Michael
    Michael Guest

  7. #7

    Default Re: C++/Xcode

    In article <google.com>,
    com (Michael Milvich) wrote:
     
    news:<google.com>... 
    >
    > I just got home and checked, it is in the "C Language Dialect" option,
    > under the Common Settings or GNU C/C++ Compiler categories.
    >
    > Michael[/ref]

    Thanks to everyone for looking into my problem. However, switching to the
    C99 mode didn't exactly fix the problem, for some reason. I did find that
    my default compiler was GCC 2.95.2, probably because I installed it after
    Xcode (necessary to compile another app). I changed the symbolic link set
    in /usr/lib/gcc/darwin to point to 3.3, but with no effect. Maybe this
    gummed up the works even more (a little knowledge is a dangerous
    thing...). Anyway, in searching through the apple web site I found and
    installed Xcode 1.1. Voila, problem solved.

    dan
    dfrank Guest

  8. #8

    Default Re: C++/Xcode

    In article
    <colorado.edu>,
    edu (dfrank) wrote:
     
    > news:<google.com>... 
    > >
    > > I just got home and checked, it is in the "C Language Dialect" option,
    > > under the Common Settings or GNU C/C++ Compiler categories.
    > >
    > > Michael[/ref]
    >
    > Thanks to everyone for looking into my problem. However, switching to the
    > C99 mode didn't exactly fix the problem, for some reason. I did find that
    > my default compiler was GCC 2.95.2, probably because I installed it after
    > Xcode (necessary to compile another app). I changed the symbolic link set
    > in /usr/lib/gcc/darwin to point to 3.3, but with no effect. Maybe this
    > gummed up the works even more (a little knowledge is a dangerous
    > thing...). Anyway, in searching through the apple web site I found and
    > installed Xcode 1.1. Voila, problem solved.
    >
    > dan[/ref]

    The more correct thing to do would have been -

    gcc_select 3.3
    lloyd Guest

Similar Threads

  1. Xcode pain in the
    By Paul in forum Mac Programming
    Replies: 2
    Last Post: January 15th, 09:13 AM
  2. What happened to XCode 1.1???
    By MacMan in forum Mac Programming
    Replies: 6
    Last Post: December 20th, 11:04 PM
  3. Cocoa + Xcode + GMP = What the?
    By M in forum Mac Programming
    Replies: 11
    Last Post: November 22nd, 11:46 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

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 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139