Bridging C++ to Cocoa?

  • Hello,

    Could someone point me to a simple example of bridging straight C++
    classes to an Objective-C/Cocoa gui?

    For example, I have several C++ classes that compile on mac, linux,
    and windows and would like to feed their output to a Objective-C/Cocoa
    based gui.  How do I go about that?  I just got started and am on the
    steep slope of the learning curve.

    Thanks much,
    graham

    I just switch to mac this year, yea!  Loving it.
  • Hi

    Have a look at Obj-C++. Basically, c++ instances can exist as
    "properties" inside any Obj-C class (compile with Obj-C++) much like
    any ansi c type or Obj-C instance.

    I use it all the time to build cocoa GUIs to stuff i have in portable c
    ++.

    I also recommend having a look at Ogre Cocoa front ends. While you may
    not be interested in Ogre itself (3D), the Cocoa samples are really
    simple and should allow you to understand how to mix c++ with Cocoa/
    Obj-C++

    Cheers,

    Filipe

    On 2007/11/17, at 16:07, Graham Reitz wrote:

    > Hello,
    >
    > Could someone point me to a simple example of bridging straight C++
    > classes to an Objective-C/Cocoa gui?
    >
    > For example, I have several C++ classes that compile on mac, linux,
    > and windows and would like to feed their output to a Objective-C/
    > Cocoa based gui.  How do I go about that?  I just got started and am
    > on the steep slope of the learning curve.
    >
    > Thanks much,
    > graham
    >
    > I just switch to mac this year, yea!  Loving it.
    >
  • Thanks Filipe,

    I looked over some of the ogre examples and it almost looks like you
    can use C++ classes right in Object-c++.  Is that right?

    graham

    On Nov 17, 2007, at 11:03 AM, Filipe Varela wrote:

    > Hi
    >
    > Have a look at Obj-C++. Basically, c++ instances can exist as
    > "properties" inside any Obj-C class (compile with Obj-C++) much like
    > any ansi c type or Obj-C instance.
    >
    > I use it all the time to build cocoa GUIs to stuff i have in
    > portable c++.
    >
    > I also recommend having a look at Ogre Cocoa front ends. While you
    > may not be interested in Ogre itself (3D), the Cocoa samples are
    > really simple and should allow you to understand how to mix c++ with
    > Cocoa/Obj-C++
    >
    > Cheers,
    >
    > Filipe
    >
    > On 2007/11/17, at 16:07, Graham Reitz wrote:
    >
    >> Hello,
    >>
    >> Could someone point me to a simple example of bridging straight C++
    >> classes to an Objective-C/Cocoa gui?
    >>
    >> For example, I have several C++ classes that compile on mac, linux,
    >> and windows and would like to feed their output to a Objective-C/
    >> Cocoa based gui.  How do I go about that?  I just got started and
    >> am on the steep slope of the learning curve.
    >>
    >> Thanks much,
    >> graham
    >>
    >> I just switch to mac this year, yea!  Loving it.
    >>
  • > I looked over some of the ogre examples and it almost looks like you
    > can use C++ classes right in Object-c++.  Is that right?

    That is not right.  I created a simple Cocoa application with the
    Xcode wizard and tried to import a really simple C++ class called
    test.hpp and the compiler had no idea what to do.

    Let's say I had the existing C++ class (below) and I wanted to use it
    in a Carbon application.  How would I go about doing that?

    Thanks much in advance,
    graham

    #ifndef _TEST_HPP_
    #define _TEST_HPP_

    #include <string>
    #include <iostream>

    class test
        {
            int m_i;
            std::string m_s;
            double m_d;
            bool m_b;

        public:
            test()
            {
                m_i = 1;
                m_s = "test";
                m_d = 1.1;
                m_b = false;
                std::cout << "test default constructor called\n";
            }

            test(int i, std::string &s, double d, bool b) :
            m_i(i), m_s(s), m_d(d), m_b(b)
            {
                std::cout << "test constructor called\n";
            }

    void get(int &i, std::string &s, double &d, bool &b)
    {
      i = m_i;
      s = m_s;
      d = m_d;
      b = m_b;
    }

            ~test()
            {
                std::cout << "test destructor called\n";
            }
        };

    #endif // _TEST_HPP_

    Any help would be greatly appreciated.

    On Nov 17, 2007, at 5:57 PM, Graham Reitz wrote:

    > Thanks Filipe,
    >
    > I looked over some of the ogre examples and it almost looks like you
    > can use C++ classes right in Object-c++.  Is that right?
    >
    > graham
    >
    > On Nov 17, 2007, at 11:03 AM, Filipe Varela wrote:
    >
    >> Hi
    >>
    >> Have a look at Obj-C++. Basically, c++ instances can exist as
    >> "properties" inside any Obj-C class (compile with Obj-C++) much
    >> like any ansi c type or Obj-C instance.
    >>
    >> I use it all the time to build cocoa GUIs to stuff i have in
    >> portable c++.
    >>
    >> I also recommend having a look at Ogre Cocoa front ends. While you
    >> may not be interested in Ogre itself (3D), the Cocoa samples are
    >> really simple and should allow you to understand how to mix c++
    >> with Cocoa/Obj-C++
    >>
    >> Cheers,
    >>
    >> Filipe
    >>
    >> On 2007/11/17, at 16:07, Graham Reitz wrote:
    >>
    >>> Hello,
    >>>
    >>> Could someone point me to a simple example of bridging straight C+
    >>> + classes to an Objective-C/Cocoa gui?
    >>>
    >>> For example, I have several C++ classes that compile on mac,
    >>> linux, and windows and would like to feed their output to a
    >>> Objective-C/Cocoa based gui.  How do I go about that?  I just got
    >>> started and am on the steep slope of the learning curve.
    >>>
    >>> Thanks much,
    >>> graham
    >>>
    >>> I just switch to mac this year, yea!  Loving it.
    >>>

  • On Nov 17, 2007, at 4:51 PM, Graham Reitz wrote:

    >
    >> I looked over some of the ogre examples and it almost looks like
    >> you can use C++ classes right in Object-c++.  Is that right?
    >
    > That is not right.  I created a simple Cocoa application with the
    > Xcode wizard and tried to import a really simple C++ class called
    > test.hpp and the compiler had no idea what to do.
    >
    > Any help would be greatly appreciated.

    The objective-c file you include this C++ class in ends in .mm right? :)

    -Shawn
  • On Nov 17, 2007, at 3:57 PM, Graham Reitz wrote:

    > I looked over some of the ogre examples and it almost looks like you
    > can use C++ classes right in Object-c++.  Is that right?

    You can use C++ classes in Objective-C class and vice versa with a few
    caveats which are covered in Apple documentation...

    <http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articl
    es/chapter_12_section_1.html#//apple_ref/doc/uid/TP30001163-CH10-SW1
    >

    -Shawn
  • I included it in the main.m file to see what happens.  Does it have to
    end in mm to compile C++ classes?

    Ok, I had better go through some of the Cocoa tutorials.

    graham

    On Nov 17, 2007, at 6:55 PM, Shawn Erickson wrote:

    >
    > On Nov 17, 2007, at 4:51 PM, Graham Reitz wrote:
    >
    >>
    >>> I looked over some of the ogre examples and it almost looks like
    >>> you can use C++ classes right in Object-c++.  Is that right?
    >>
    >> That is not right.  I created a simple Cocoa application with the
    >> Xcode wizard and tried to import a really simple C++ class called
    >> test.hpp and the compiler had no idea what to do.
    >>
    >> Any help would be greatly appreciated.
    >
    > The objective-c file you include this C++ class in ends in .mm
    > right? :)
    >
    > -Shawn
  • On Nov 17, 2007, at 5:03 PM, Graham Reitz wrote:

    > I included it in the main.m file to see what happens.  Does it have
    > to end in mm to compile C++ classes?
    >
    > Ok, I had better go through some of the Cocoa tutorials.

    .m = Objective-C
    .mm = Objective-C++

    Xcode knows what to do with those file endings automatically or you
    can tell Xcode how to treat a given file if you want but I use the .mm
    naming myself to make it clear and keep it automatic.

    -Shawn
  • Thanks!  That's just what I need.

    On Nov 17, 2007, at 6:59 PM, Shawn Erickson wrote:

    >
    > On Nov 17, 2007, at 3:57 PM, Graham Reitz wrote:
    >
    >> I looked over some of the ogre examples and it almost looks like
    >> you can use C++ classes right in Object-c++.  Is that right?
    >
    > You can use C++ classes in Objective-C class and vice versa with a
    > few caveats which are covered in Apple documentation...
    >
    > <http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articl
    es/chapter_12_section_1.html#//apple_ref/doc/uid/TP30001163-CH10-SW1
    > >
    >
    > -Shawn
previous month november 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    
Go to today