C++ and macs...

Discussion in 'Mac Apps and Mac App Store' started by Rezet, Sep 7, 2003.

  1. Rezet macrumors 6502a

    Rezet

    Joined:
    Apr 21, 2003
    Location:
    Connecticut, United States of America
    #1
    Hey my frind was wondering how C++ works on mac. He is a PC programmer and always thought thet one cannot use C++ on macs. I don't program anything like that so i really can't give specific answers. could anyone post some keypoint on how C++ works on macs? Like what programs one need to get where to get em? Is it same as on PC? etc...
     
  2. FattyMembrane macrumors 6502a

    FattyMembrane

    Joined:
    Apr 14, 2002
    Location:
    bat country
    #2
    pretty much every language available works on the mac os. project builder (the free development tools included with osx) allows you to code in c++. most windows users have absolutely no idea what you can or can't do with a mac; if they did, they wouldn't be windows users any more :D .

    but yeah, c++ works like it would on any other system. you can compile it from the command-line like on unix systems, or in project builder / codewarrior.

    P.S. things like the finder, quicktime, and itunes (any carbon app for that matter) are written in c++
     
  3. MisterMe macrumors G4

    MisterMe

    Joined:
    Jul 17, 2002
    Location:
    USA
    #3
    To amplify your point, through System 6.0.8, the Mac operating system was written in Pascal-assisted 68000 assembly language. However, C++ has been the language of choice for Mac programming for more than a decade. Except for the legacy portions of the OS, System 7.0 through MacOS 9.2.2 were written in C++. IIRC, C++ remains the language of Carbon.
     
  4. NavyIntel007 macrumors 65816

    NavyIntel007

    Joined:
    Nov 24, 2002
    Location:
    Tampa, FL
    #4
    gcc is pretty up to date on the command line side.

    Rezet, love your quote buddy.
     
  5. zimv20 macrumors 601

    zimv20

    Joined:
    Jul 18, 2002
    Location:
    toronto
    #5
    osx is unix. just about every language under the sun (no pun intended) can be developed on unix. tell your friend that.

    many people, myself included, feel that unix is by far the best development platform.
     
  6. crenz macrumors 6502a

    crenz

    Joined:
    Jul 3, 2003
    Location:
    Shanghai, China
    #6
    Re: C++ and macs...

    There's two issues here: language and development environment.

    As a programmer, he should be aware that all programming languages are in general platform-ignorant; they can be used anywhere. (A special case is e.g. Visual Basic; while Basic can be used anywhere, Visual Basic has been heavily modified by Microsoft towards use on Windows. But even for VB, there's a compatible product available on Mac: RealBasic).

    However, the key thing is the development environment. On Windows, Microsoft has created a fantastic IDE for C++ ("integrated development environment"), Visual C++ . It helps programmers to be much more productive by organizing their work. I'm not aware of any software on Linux that has the same functionality (notice that IDEs have not been invented by MS, though; e.g. Borland has been producing them for years (and in a great way!) as well). Visual C++ and associated products are rather expensive, unless you are a student.

    For Mac OS X, Apple ships the Project Builder for free, with every copy of Mac OS X. I am convinced that the influx of tools for OS X is mostly due to the PB. It provides an easy and intuitive way to code apps on the Mac. Yes, it's different from MSVC and takes a bit getting used to, but it has lots of functionality. And I'm convinced it's as productive as MSVC.

    And the best thing is: Things are going to be even better in Panther with Xcode. An article recently linked on MacBytes.com touted Xcode as something like the "better C++" and praised Apple for making things so much easier for programmers. I'm really curious to check out that one...

    As an addendum, let me say that Mac OS X also lets you develop in Objective C, AppleScript (allows for GUI apps as well!), Perl, Python, PHP out of the box. As in: Everything is included with the copy of X.2 you bought.
     
  7. zimv20 macrumors 601

    zimv20

    Joined:
    Jul 18, 2002
    Location:
    toronto
    #7
    IDEs exist on many platforms for many different languages. using the MS offering as the standard against which to measure others is about as useful as holding Pascal as the standard programming language.

    i first noticed IDEs popping up in the mid 80s. the first i used was Lightspeed Pascal and Lightspeed C on the mac, around 1986 iirc.
     
  8. crenz macrumors 6502a

    crenz

    Joined:
    Jul 3, 2003
    Location:
    Shanghai, China
    #8
    Well, I'd say it is about as useful as using C++ as the standard for complex application development. There is a difference between using something as a standard for comparison and declaring something "the" standard.

    Imagine the Project Builder would only support Pascal. Obviously, you'd want to compare Project Builder/Pascal against e.g. KDevelop/gcc, MSVC, Interface Builder/Qt and wxWindows (oops, runs on Mac also :)) to see whether development on the Mac platform is as full-featured as it is on Linux and Windows. If it were deficient, it wouldn't give you the option to use MSVC instead (since you want to use a Mac), but it would give you an excuse to kick Apple's behind.

    I think MSVC6 is an excellent IDE, even though it is geared towards C++ (which I use, but hate) and Windows (which I only use to develop software for clients). For many (a majority of GUI application developers?), it is the IDE, since Windows/C++ is their only market.

    That's why I use MSVC here to illustrate that Apple plays (almost) in the same league. I couldn't use e.g. Delphi, because (unfortunately) not so many people care about Delphi/Kylix anymore...
     
  9. crenz macrumors 6502a

    crenz

    Joined:
    Jul 3, 2003
    Location:
    Shanghai, China
    #9
    wxWindows

    Just remembered something. Point your friend to http://www.wxwindows.org/ . wxWindows is a free, open-source toolkit that lets you develop GUI apps for Linux, Windows, OS 9 and OS X. For many apps, you can even just recompile the code to port it to another platform. I'm a huge fan of it, since (even if you don't need the cross-platformness) it makes Windows programming so much more easy and logical (MFC is not so much fun to use... :( ).
     
  10. Fender2112 macrumors 6502a

    Fender2112

    Joined:
    Aug 11, 2002
    Location:
    Charlotte, NC
    #10
    a bit off topic...

    What does iirc mean? I've seen it quite a bit in tha past several weeks. I though it was a typo for IRC but I don't think all these folks are making the same mistake. :)
     
  11. MisterMe macrumors G4

    MisterMe

    Joined:
    Jul 17, 2002
    Location:
    USA
    #11
    Re: a bit off topic...

    IIRC, IIRC means If I Remember Correctly.
     
  12. cubist macrumors 68020

    Joined:
    Jul 4, 2002
    Location:
    Muncie, Indiana
    #12
    IIRC, Carbon is mostly programmed using straight C.
     
  13. synthetickittie macrumors regular

    Joined:
    Dec 17, 2002
    Location:
    Boston
    #13
    anyone have a clue why when I used project builder to do my homework, intoduction to computer science(c++ coding), it will not compile things I write.

    The steps I take are as follows:

    1) open project builder and click file-> new project.

    2) from the menu that pops up I choose "c++ tool" from under the "tool" header

    3) name the project any random name

    4)In the source folder on the left side I click on "main.cpp"

    5) on the right side I code:

    #include <iostream>

    int main ()
    {
    std::cout << "Test\n";
    return 0;
    }

    6) file->save

    7)build-> build and run

    After that tells me the build failed with 79 errors. Im new to coding, well at least c++ Ive only done web based coding before, and my teaches by what we use in our lab section(first one is tomorrow) which are unix shells and I know I could do the same within the terminal but the way we have to compile them in the lab it with a compiler on that computer which I do not have access of.
     
  14. bousozoku Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #14
    I just created the project, pasted your code, and it compiled and ran fine. Perhaps, it's something else? You might post some of the errors.

    cubist:

    Of course, you can use Carbon within C or C++ but the bindings are strictly C.

    zimv20:

    I believe that Borland are credited with the first IDE in Turbo Pascal 3.0 in 1985. The LightSpeed IDEs were slicker though.
     
  15. zimv20 macrumors 601

    zimv20

    Joined:
    Jul 18, 2002
    Location:
    toronto
    #15
    Re: Re: a bit off topic...

    ah, ambiguity strikes again. i always thought it was "if i recall correctly"

    both work, obviously
     
  16. zimv20 macrumors 601

    zimv20

    Joined:
    Jul 18, 2002
    Location:
    toronto
    #16
    i haven't coded c++ since '98, really, but i'd try:

    Code:
    #include <iostream.h>
    
    int main (int argc, char** argv) 
    {
        cout << "Test" << endl;
        return 0;
    }
    
     
  17. bousozoku Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #17
    That's fine with compilers prior to the standard, but the header files have changed names since then.
     
  18. zimv20 macrumors 601

    zimv20

    Joined:
    Jul 18, 2002
    Location:
    toronto
    #18
    !!!!!!

    what happened?
     
  19. Santiago macrumors regular

    Joined:
    Jun 14, 2002
    Location:
    Mountain View, California
    #19
    The correct name for all built-in C++ headers is a single lowercase word, without a ".h" at the end. For built-in C headers, they can be included via their original names, or via their original names with the ".h" chopped off and a "c" added in front. (e.g. "<cstdlib>" or "<stdlib.h>")

    Note that string and string.h/cstring are completely different files. string contains C++ string objects. string.h/cstring contains C functions.
     
  20. zimv20 macrumors 601

    zimv20

    Joined:
    Jul 18, 2002
    Location:
    toronto
    #20
    thanks for the info
     
  21. jettredmont macrumors 68030

    Joined:
    Jul 25, 2002
    #21
    Most likely one of thos 76 errors came from the linker and said something like "could not find main". "main" needs to have two arguments in c/c++; anything else just won't work:

    int mainc ( int argc, char* argv[] );

    (argv can be char** too, maybe even char * const argv[] or somesuch ... but it's gotta be there!)

    In general, you just need to look at the first 1-2 errors you get, fix those, and try compiling again. Oftentimes, one error in code will cause many errors in the compiler.

    OTOH, 76 seems like a lot of errors. Not sure if this error would cause that many.
     
  22. jettredmont macrumors 68030

    Joined:
    Jul 25, 2002
    #22
    This would work, except you need to preface "cout" and "endl" with "std::" or (more likely) put "using namespace std;" after the include line at the top.
     
  23. jettredmont macrumors 68030

    Joined:
    Jul 25, 2002
    #23
    Re: C++ and macs...

    C++ works great on the Mac, whether you prefer a full-featured IDE (Project Builder) or a command line (emacs/vi + gcc).

    You will NOT find MFC on the Mac (as though you wanted to ...) You will instead find Cocoa.

    Also, while interface programming in MSVC is done entirely in straight C (or pidgin C++ with MFC), interface programming on the Mac is generally done in Objective C or Java (there is a C++ Cocoa wrapper I believe, but no one uses it because it makes more sense to use Obj-C/C++ for the UI).

    With the inclusion of ObjC++ in gcc3 last year, it is very easy to use a C++ cross-platform code base with a Cocoa/ObjC++ front end (prior to ObjC++ you would have had to make your core application a library with a C API, then link your ObjC front end to it ... doable but kludgy).

    Personally, I find Project Builder to be a vastly superior coding environment to MSVC++. Heck, for one thing, the performance-optimizing tools (Sampler, etc) are about 100x easier to use than Microsoft's "Easy 15-step, Recursive, CLI-only and you figure out how to interpret the entrails PROFILE procedure".

    The only killer on the Mac currently is that gcc (the compiler ProjectBuilder uses) is incredibly slow to build compared to MSVC's cc, and the output is highly less optimized than the Windows output. On a G4/733 my compile times are 30-45 minutes; on a P4 1.5GHz the same compile (with a Windows front end intstead of a Cocoa front end of course, but otherwise the same code) takes 5-7 minutes. A dual 1.42GHz Mac still takes 15 minutes, which brings it into the reasonable realm, but still a lot slower than the PC. That's the only thing that keeps my primary development machine as a PC today.

    I only have XCode's initial Jaguar release (I can't spare a machine for Panther betas so I haven't gotten an updated XCode), and, aside from performance problems (100% CPU while sitting idle for a day ... not doing a rendezvous bulid for anyone else either ...) it is a huge advance. Before I gave up on it, I was using it to get my half-hour builds done faster than the seven minutes it takes on my Windows box, which was a first.

    So, I'd recommend your friend try Panther (when it comes out) or Jaguar (today) for C++ development. I suspect he wouldn't at all be disappointed by the development experience that will come shipped with a new G5 after Panther ships.
     
  24. bousozoku Moderator emeritus

    Joined:
    Jun 25, 2002
    Location:
    Gone but not forgotten.
    #24
    That's fine except that I pasted his source code into a new project and I got zero complaints and it rain perfectly.
     
  25. zimv20 macrumors 601

    zimv20

    Joined:
    Jul 18, 2002
    Location:
    toronto
    #25
    ahhhh, yes. the namespace stuff was just being hammered out when all my projects went java.

    C++ old skool, yo. ;-)
     

Share This Page