C++ Compiler For Mac?

Discussion in 'Mac Programming' started by CS5679, Jan 31, 2011.

  1. CS5679 macrumors newbie

    Joined:
    Jan 18, 2011
    #1
    What is a good C++ complier for Mac? Any help is greatly appreciated!
     
  2. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #2
    g++ is the standard one included with Xcode. I suggest you use that. When Xcode 4 is released you'll also have clang++.

    There are other options such as the Intel C++ compiler but they cost quite a bit of cash.
     
  3. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
  4. CS5679 thread starter macrumors newbie

    Joined:
    Jan 18, 2011
    #4
    Thanks guys! But... I don't understand two things, I am new to programming so bear with me.

    1. How do you get C ++ working in Xcode.
    2. And if you can't get C++ working, what other complier is available for mac?
     
  5. balamw, Feb 4, 2011
    Last edited: Feb 4, 2011

    balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #5
    Start Xcode. (Applies to Version 3.2.5).
    Create New Xcode Project.
    Select Mac OS -> Application -> Command Line Tool.
    Select "C++ stdc++" from the Type drop down box.

    Or, install Xcode, but first learn how to use g++ without the IDE.

    Question: If you are new to programming, why are you learning C++ first? What is your goal? What resources are you using to learn? Books? Courses? ...

    EDIT: See http://forums.macrumors.com/showthread.php?t=1090449 for a possibly useful related read.

    B
     
  6. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #6
    1. Complier is not a word in the English language, and it is painful to read. "Compiler" is derived from "compile", not from "comply".

    2. The standard XCode installation comes with C, C++, Objective-C, and Objective-C++. GAS (gnu assembler) if you are a masochist. On top of that you can use Perl, Python, Ruby out of the box (they don't use compilers. Well, kind of). You can apparently get Pascal and Fortran compilers, as well as Java compilers.
     
  7. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #7
    Sure it is. What would you refer to one who complies as? Is it painful to read because you hate complying?

    =)

    -Lee
     
  8. CS5679 thread starter macrumors newbie

    Joined:
    Jan 18, 2011
    #8
    Ok first I would like to thank balamw for all his help!

    If I may for a second explain my situation, so that you guys can understand whats going on a little better, and maybe can give me some pointers. I am currently attending a small liberal arts college, that has a computer science degree available. This semester is my first semester to have any type of programming classes so I am new to this whole programming thing, I am currently taking programming 1, the professor, is using this book as his approach to programming heres the link.. C++ Textbook I don't understand the teacher when he teaches, so I have no clue what is going on I have asked for help and he is not very helpful. To answer balamw questions': I have no idea why my teacher has chose C++ as our first language, my goal is to learn how to program a little bit and do it effectively to move on to programming 2. So.. If you guys could point me in the right direction maybe give me some pointers on 1). what compiler I could use on Mac for C ++ 2). And any other pointers for me while I am learning to program! Thanks everybody!

    Note: A fellow classmate told me today that he heard C++ was Windows only language is this true? Is this why there is not much support on the mac for it?
     
  9. (marc) macrumors 6502a

    (marc)

    Joined:
    Sep 15, 2010
    Location:
    the woods
    #9
    Read the first answer.

    0x3A28213A
    0x6339392C
    0x7363682E

    Your classmate is wrong. You can use C++ on all popular OSen and on many embedded systems, too.

    C++ support on the Mac is great.
     
  10. gnasher729 macrumors P6

    gnasher729

    Joined:
    Nov 25, 2005
    #10
    To the contrary, Windows is about the only OS where you don't get a standard conforming C++ and C compiler.
     
  11. TBi macrumors 68030

    TBi

    Joined:
    Jul 26, 2005
    Location:
    Ireland
    #11
    Thanks! Have you any pointers for 64 bit programming? :)
     
  12. balamw Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #12
    However, given the choice of textbooks, I'm not sure a standard conforming compiler is what is needed. It looks like most of the book is dealing with DarkGDK from the reviews at Amazon.

    In order to use DarkGDK you will need at least Visual C++ 2008 Express.

    Time to get yourself a copy of Virtualbox and a Windows license. :(

    B
     
  13. CS5679 thread starter macrumors newbie

    Joined:
    Jan 18, 2011
    #13
    Okay several more questions…

    1.) What is G++? My teacher said he has never heard of it! lol
    2.) balamw, on that link to that thread you gave me, I noticed that me and this person are in the same boat, I have tried to the "hello world" program just like he did this morning using Xcode with the instructions you gave me...

    Create New Xcode Project.
    Select Mac OS -> Application -> Command Line Tool.
    Select "C++ stdc++" from the Type drop down box.

    and my program still did not work!
     
  14. CS5679 thread starter macrumors newbie

    Joined:
    Jan 18, 2011
    #14
    Here are some pics of my attempt to run the program!
     
  15. CS5679 thread starter macrumors newbie

    Joined:
    Jan 18, 2011
    #15
    sorry! Cant' get the pictures to work, here is a second try!
     

    Attached Files:

  16. notjustjay macrumors 603

    notjustjay

    Joined:
    Sep 19, 2003
    Location:
    Canada, eh?
    #16
    "g++" is the command name for the Gnu C++ compiler. The Gnu C compiler is called "gcc".

    These tools exist for a huge variety of platforms, by the way, including Macs, PCs running Windows, Linux, Sun OS, and all kinds of other platforms. The intent is that the code you write on one platform can compile on others with relatively few modifications. And, yes, the code can run on all kinds of embedded platforms too. I have personally written C/C++ code that is running in a telephone switch, a robot (back in university), and on a mission computer installed in a helicopter.

    If your teacher has never heard of gcc/g++ then be aware that may not have a whole lot of programming experience either. We've seen plenty of examples of people coming here for help because they're confused -- and often, it's because whoever is teaching them isn't doing a very good job.

    I'm not trying to slag anyone, just be aware that the teachers sometimes get it wrong too, so make sure you read and experiment on your own.

    With respect to your screen shot: That looks like it ought to work. Were there compile errors? Does it not run? Keep in mind that it will output to a Unix "console" output, not a dialog box or window, so you might not see the output at all unless you run your new program from the Terminal.
     
  17. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #17
    Looks fine, as notjustjay said. You need to open the console from the "Run" menu to see your output, but otherwise you should be fine.

    So far you've said you don't understand when your teacher teaches (the blame can be shared, teaching and learning styles can just be incompatible), but then that when you ask for help they don't provide it (that is their fault). This is a problem that's bigger than any particular programming issue or environment issue. If you can't learn from this person and they aren't providing usable assistance outside of class when requested, you shouldn't be paying to teach yourself. You said it was a small college, so there may not be other sections of the class, but if there are you should transfer. If you need this credit and no other professor teaches it (you said teacher not professor, which is concerning, too unless that's just a parlance issue) then you might go to the department head, ombudsman, etc. and explain your situation to see if they can provide other resources. Even if they can't, they need to know if a student is suffering. Maybe there are some grad students, tutors, etc. that can help. We can try to fill that role, but you are paying the school and not paying us. We are happy to help, but we can't really provide a formal education.

    If your teacher has never heard of g++ and they teach a C++ class this is a serious red flag. Either they don't believe in OSes other than Windows or they don't actually know C++. Neither of these is a big positive.

    I think you are going to be able to use XCode without issue once you pop the console open, but I would beg that you test out writing code in an editor like Smultron or TextWrangler (other have recommended these, I have not used them myself), then compile and debug your code from a Terminal prompt. If you haven't used a terminal before this may seem a little scary, but it will build character and you will be better for it.

    Good luck in both learning to program and getting out of this class. If you can't get help from higher up in the department that says a bad thing about it and transferring out of the class may be ineffective, and transferring to a different school might behoove you. I transferred after my first year at University to a much better school and it made a huge difference. You shouldn't do so based on an anonymous stranger on the internet, but if there is a culture mismatch between yourself and the faculty and staff at your school you're going to suffer.

    -Lee
     
  18. notjustjay macrumors 603

    notjustjay

    Joined:
    Sep 19, 2003
    Location:
    Canada, eh?
    #18
    Here's how to get the Hello World program compiling (assuming your tools are installed):

    Open Terminal.
    "cd" to the directory where your main.cpp file is.
    Type: "g++ main.cpp"
    The compiler will run and compile your file into an executable called "a.out".
    Run it by typing: "./a.out"

    You should see "Hello World!" appear on the next line.

    Once you've got that far, start experimenting. Change "Hello World" to other things. Get used to the edit-compile-run, edit-compile-run cycle. Then you'll be in good shape to start learning more.
     
  19. Detrius macrumors 68000

    Joined:
    Sep 10, 2008
    Location:
    Asheville, NC
    #19
    That's just mean. You have no way of knowing what will happen when those pointers are dereferenced. You may as well have just sent the OP to 0xDEADBEEF. At least then you'd KNOW the program would crash.

    Speaking of hex, facebook's IPv6 address is 2620:0:1cfe:face:b00c::3. Ha! Hex humor. :)
     

Share This Page