Unable to compile Cocoa/Objective-C program to C++

  • In my Cocoa/Objective-C program I'm trying to access 3rd party
    software written in C++.

    I'm trying to use Objective-C++ to accomplish this but it appears that
    Xcode is not recognizing the file where I call the C++ as having been
    written in Objective-C++. (The long compiler command contains '-x
    objective-c'.) I've renamed the file to give it a .mm extension, which
    is the extension used for Objective-C++ files, and I've also set the
    File Type to 'Default- Objective-C++' in the Identity and Type section
    of the File Inspector. I also removed the Objective-C++ file from my
    project and reinserted it.)

    I #include one header from the 3rd party software and have one line
    that calls the software to instantiate a C++ object there. This header
    file references other header files and one of them has the line
    '#include <string>'. The compiler complains that it can't find the
    file 'string'.

    I used the 'locate' command in Terminal to find the 'string' file, and
    found two occurrences, one at /usr/include/c++/4.2.1/string and
    another at /usr/lib/c++/v1/string.

    I've tried adding /usr/include/c++/4.2.1 to the HEADER_SEARCH_PATHS in
    Xcode but get lots of additional compile errors.

    Can someone help me with this issue with calling C++?
  • I am able to compile my one Objective-C++ file as Objective-C++. (I
    selected the Build Phases tab for the project I expanded the Compile
    Sources section and on the line for the Objective-C++ file I added in
    the Compiler Flags column: '-x objective-c++'.

    When I do this, this compiler is called twice, one to compile the
    Objective-C file and one to compile the Objective-C++ file.

    I'm still getting a fatal compile error in one of the header files
    #included in the 3rd party software though.

    (If I compile the Objective-C++ file, by a calling clang in  Terminal,
    I can compile the Objective-C++ file with just one warning message, so
    I'm definitely getting closer to solving this problem.)

    On Sun, May 12, 2013 at 11:03 AM, Paul Johnson <paul...> wrote:
    > In my Cocoa/Objective-C program I'm trying to access 3rd party
    > software written in C++.
    >
    > I'm trying to use Objective-C++ to accomplish this but it appears that
    > Xcode is not recognizing the file where I call the C++ as having been
    > written in Objective-C++. (The long compiler command contains '-x
    > objective-c'.) I've renamed the file to give it a .mm extension, which
    > is the extension used for Objective-C++ files, and I've also set the
    > File Type to 'Default- Objective-C++' in the Identity and Type section
    > of the File Inspector. I also removed the Objective-C++ file from my
    > project and reinserted it.)
    >
    > I #include one header from the 3rd party software and have one line
    > that calls the software to instantiate a C++ object there. This header
    > file references other header files and one of them has the line
    > '#include <string>'. The compiler complains that it can't find the
    > file 'string'.
    >
    > I used the 'locate' command in Terminal to find the 'string' file, and
    > found two occurrences, one at /usr/include/c++/4.2.1/string and
    > another at /usr/lib/c++/v1/string.
    >
    > I've tried adding /usr/include/c++/4.2.1 to the HEADER_SEARCH_PATHS in
    > Xcode but get lots of additional compile errors.
    >
    > Can someone help me with this issue with calling C++?
  • This is a bit of a shot in the dark, but are you by any chance including a C++ header in your Objective-C++ header file?  This would account for the error you are seeing.

    Here is a typical pattern:  ObjC.m  includes  ObjC++.h.  ( ObjC++.mm also includes ObjC++.h ).  ObjC++.h must contain obnly Objective-C since it will be included by an Objective-C class.  If you use any C++ types in ObjC++.h, compilation of ObjC.m will fail, so you need to completely encapsulate all of your C++ code within .mm files.

    Hope this helps.  If not, maybe send some of your code?

    - Dan Treiman

    On May 12, 2013, at 12:06 PM, Paul Johnson <paul...> wrote:

    > I am able to compile my one Objective-C++ file as Objective-C++. (I
    > selected the Build Phases tab for the project I expanded the Compile
    > Sources section and on the line for the Objective-C++ file I added in
    > the Compiler Flags column: '-x objective-c++'.
    >
    > When I do this, this compiler is called twice, one to compile the
    > Objective-C file and one to compile the Objective-C++ file.
    >
    > I'm still getting a fatal compile error in one of the header files
    > #included in the 3rd party software though.
    >
    > (If I compile the Objective-C++ file, by a calling clang in  Terminal,
    > I can compile the Objective-C++ file with just one warning message, so
    > I'm definitely getting closer to solving this problem.)
    >
    > On Sun, May 12, 2013 at 11:03 AM, Paul Johnson <paul...> wrote:
    >> In my Cocoa/Objective-C program I'm trying to access 3rd party
    >> software written in C++.
    >>
    >> I'm trying to use Objective-C++ to accomplish this but it appears that
    >> Xcode is not recognizing the file where I call the C++ as having been
    >> written in Objective-C++. (The long compiler command contains '-x
    >> objective-c'.) I've renamed the file to give it a .mm extension, which
    >> is the extension used for Objective-C++ files, and I've also set the
    >> File Type to 'Default- Objective-C++' in the Identity and Type section
    >> of the File Inspector. I also removed the Objective-C++ file from my
    >> project and reinserted it.)
    >>
    >> I #include one header from the 3rd party software and have one line
    >> that calls the software to instantiate a C++ object there. This header
    >> file references other header files and one of them has the line
    >> '#include <string>'. The compiler complains that it can't find the
    >> file 'string'.
    >>
    >> I used the 'locate' command in Terminal to find the 'string' file, and
    >> found two occurrences, one at /usr/include/c++/4.2.1/string and
    >> another at /usr/lib/c++/v1/string.
    >>
    >> I've tried adding /usr/include/c++/4.2.1 to the HEADER_SEARCH_PATHS in
    >> Xcode but get lots of additional compile errors.
    >>
    >> Can someone help me with this issue with calling C++?
    > _______________________________________________
    > Do not post admin requests to the list. They will be ignored.
    > Xcode-users mailing list      (<Xcode-users...>)
    > Help/Unsubscribe/Update your Subscription:
    > https://lists.apple.com/mailman/options/xcode-users/<dtreiman...>
    >
    > This email sent to <dtreiman...>
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