Xcode cocoa project with c++

  • Hi
    i'm writing a project wihich will use mix of objective-c and c++.
    I've created a bundle with added c+ files and i'm trying to build that bundle.
    My c++ files has h/cpp extensions and bundle has option to compile files depending on the extension.
    On compile i got a lot of errors (more than 2000).
    Seems that xcode is looking through the headers of the cocoa foundation framework and find there alot of 'errors'.
    f.e.: In file NSObjCRuntime.h it has found that string
        @class NSString;
    has error
        expected unqualified-id before '@' token

    how i can fix that problem ?
    PS:those c++ files has no imports of any cocoa headers, but use xerces headers; compiled xerces framework with added headers is added to the main project

    thanx


    ---------------------------------
    Yahoo! Answers - Get better answers from someone who knows. Tryit now.
  • On Dec 14, 2007 4:23 AM, _ _ <mcsimer...> wrote:
    > Hi
    > i'm writing a project wihich will use mix of objective-c and c++.
    > I've created a bundle with added c+ files and i'm trying to build that bundle.
    > My c++ files has h/cpp extensions and bundle has option to compile files depending on the extension.
    > On compile i got a lot of errors (more than 2000).
    > Seems that xcode is looking through the headers of the cocoa foundation framework and find there alot of 'errors'.
    > f.e.: In file NSObjCRuntime.h it has found that string
    > @class NSString;
    > has error
    > expected unqualified-id before '@' token
    >
    > how i can fix that problem ?

    You using a prefix header (pre-compiled header)? Likely the prefix
    header isn't wrapping the import of Cocoa related frameworks, etc.
    with #ifdef __OBJC__.

    When in doubt I suggest you pre-compile one of the files that has
    compile problems and look at what is getting included.

    -Shawn
  • --- Shawn Erickson <shawnce...> wrote:

    > On Dec 14, 2007 4:23 AM, _ _ <mcsimer...>
    > wrote:
    >> Hi
    >> i'm writing a project wihich will use mix of
    > objective-c and c++.
    >> I've created a bundle with added c+ files and i'm
    > trying to build that bundle.
    >> My c++ files has h/cpp extensions and bundle has
    > option to compile files depending on the extension.
    >> On compile i got a lot of errors (more than 2000).
    >> Seems that xcode is looking through the headers of
    > the cocoa foundation framework and find there alot
    > of 'errors'.
    >> f.e.: In file NSObjCRuntime.h it has found that
    > string
    >> @class NSString;
    >> has error
    >> expected unqualified-id before '@' token
    >>
    >> how i can fix that problem ?
    >
    > You using a prefix header (pre-compiled header)?
    > Likely the prefix
    > header isn't wrapping the import of Cocoa related
    > frameworks, etc.
    > with #ifdef __OBJC__.
    >
    > When in doubt I suggest you pre-compile one of the
    > files that has
    > compile problems and look at what is getting
    > included.
    >
    > -Shawn
    >

    Thank you for reply
    I've resolved my problem and want to share the
    problem's solution.

    The problem was indeed in the pre-compile header.
    When one create cocoa project it will have file
    <Project_name>_Prefix.pch with guarded section

    #ifdef __OBJC__
        #import <Cocoa/Cocoa.h>
    #endif

    which will prevent precompilation with compiler other
    than objective-c.

    My case was a bit different - i've added a bundle,
    which has a pre-compile option turned on by default,
    but header used for pre-compilation was AppKit.h,
    which has no objective-c guard. So, when i added c++
    files and tried to compile bundle, c++ compiler went
    into the AppKit.h header and started to 'pre-compile'
    objective-c code. That leads to more than 4000
    'errors' during the compilation.

    Posible solutions may be: turn off pre-compilation
    (and slow down compilation process) or write your own
    header for the pre-compilation with includes of c++
    and objective-c headers but with right guards for each
    language.

    Hope this will save a bit of time to someone.

          __________________________________________________________
    Sent from Yahoo! Mail - a smarter inbox http://uk.mail.yahoo.com
  • Hi,
    I met a problem some days ago like yours somehow.

    I have a carbon app which calls a cocoa bundle. when I want to add
    the "NSApplicationLoad()" function into my carbon app, though I've
    already added the cocoa framework and included the <Cocoa.Cocoa.h>
    head file in my .cpp file, when I compile my project, 2000+ errors
    come out, also I see "error: expected unqualified-id before '@' token".

    Someone tells me to right-click my .cpp file, choose "Get Info", in
    "File Type:" popup-button, change the "sourcecode.cpp.cpp" into
    "sourcecode.cpp.objcpp"". Recompile it, and everything is ok~

    Hope this can be helpful.

    On Dec 19, 2007, at 8:03 PM, _ _ wrote:

    >
    > --- Shawn Erickson <shawnce...> wrote:
    >
    >> On Dec 14, 2007 4:23 AM, _ _ <mcsimer...>
    >> wrote:
    >>> Hi
    >>> i'm writing a project wihich will use mix of
    >> objective-c and c++.
    >>> I've created a bundle with added c+ files and i'm
    >> trying to build that bundle.
    >>> My c++ files has h/cpp extensions and bundle has
    >> option to compile files depending on the extension.
    >>> On compile i got a lot of errors (more than 2000).
    >>> Seems that xcode is looking through the headers of
    >> the cocoa foundation framework and find there alot
    >> of 'errors'.
    >>> f.e.: In file NSObjCRuntime.h it has found that
    >> string
    >>> @class NSString;
    >>> has error
    >>> expected unqualified-id before '@' token
    >>>
    >>> how i can fix that problem ?
    >>
    >> You using a prefix header (pre-compiled header)?
    >> Likely the prefix
    >> header isn't wrapping the import of Cocoa related
    >> frameworks, etc.
    >> with #ifdef __OBJC__.
    >>
    >> When in doubt I suggest you pre-compile one of the
    >> files that has
    >> compile problems and look at what is getting
    >> included.
    >>
    >> -Shawn
    >>
    >
    > Thank you for reply
    > I've resolved my problem and want to share the
    > problem's solution.
    >
    > The problem was indeed in the pre-compile header.
    > When one create cocoa project it will have file
    > <Project_name>_Prefix.pch with guarded section
    >
    > #ifdef __OBJC__
    > #import <Cocoa/Cocoa.h>
    > #endif
    >
    > which will prevent precompilation with compiler other
    > than objective-c.
    >
    > My case was a bit different - i've added a bundle,
    > which has a pre-compile option turned on by default,
    > but header used for pre-compilation was AppKit.h,
    > which has no objective-c guard. So, when i added c++
    > files and tried to compile bundle, c++ compiler went
    > into the AppKit.h header and started to 'pre-compile'
    > objective-c code. That leads to more than 4000
    > 'errors' during the compilation.
    >
    > Posible solutions may be: turn off pre-compilation
    > (and slow down compilation process) or write your own
    > header for the pre-compilation with includes of c++
    > and objective-c headers but with right guards for each
    > language.
    >
    > Hope this will save a bit of time to someone.
    >
  • Le 19 déc. 07 à 14:51, Constantine a écrit :

    > Hi,
    > I met a problem some days ago like yours somehow.
    >
    > I have a carbon app which calls a cocoa bundle. when I want to add
    > the "NSApplicationLoad()" function into my carbon app, though I've
    > already added the cocoa framework and included the <Cocoa.Cocoa.h>
    > head file in my .cpp file, when I compile my project, 2000+ errors
    > come out, also I see "error: expected unqualified-id before '@'
    > token".
    >
    > Someone tells me to right-click my .cpp file, choose "Get Info", in
    > "File Type:" popup-button, change the "sourcecode.cpp.cpp" into
    > "sourcecode.cpp.objcpp"". Recompile it, and everything is ok~
    >
    > Hope this can be helpful.

    Renaming your .cpp into a .mm (ObjC++) will also do the trick.
previous month december 2007 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