Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C++ on a Mac for beginners?

  1. May 14, 2007 #1

    For my summer project I am going to be writing some C++ code. My computer is a Mac running OS X. I really don't know where to start. I have programmed Java on my Mac previously without too many problems, although I was struggling with setting up XCode. Now with C++, which seems much less user friendly and pretty I have no idea where to start. I need something for boneheads just to set it all up. Once the machine is set up for me to input code, I am fine. Just finding a solid interface that isn't too cold or involved. I am very unfamiliar with all the techie talk and computer science that goes into this stuff, so all the resources are over my head since they seem to assume that I am already programming on my Mac. Also, I need figure out to set up ROOT on my comp, and I have no clue where to start with that either! Any advice is greatly appreciated.

  2. jcsd
  3. May 14, 2007 #2

    I'm a fellow Mac user, but I don't program in C++ or Java. However, I can tell you that if you install the Apple Developer Tools, the latest version of which is available for free download from Apple, you're equipped with the GNU command line compilers and debuggers and the whole shebang. You can program from a terminal window or use XCode. On the rare occasions when I need to code in C, I just use gcc from a terminal; I don't understand XCode. Of course you can use any editor you want to use. I like TextWrangler from BareBones (the BBEdit folks). It's completely free and it's a powerful editor.

    As long as you're using the account you set up when you got your Mac, there's no need to set up root. The default account has admin privileges and anything that requires anything more can be done using sudo.

    Hope that helps.
  4. May 15, 2007 #3
    Ok cool. I don't know what the deal with XCode is, that program was making me batty before. I couldn't figure out how to set it up, couldn't compile my Java code, and I finally just gave up and used JJEdit. I would, for this project, like to use a nicer IDE just because I know it is going to be a bit more involved than programming cute hangman games. I will get those developer tools from mac's website. I have seen them before, and in fact I think I did have them installed before, so I will have to look and see if I still have them.

    About ROOT, it is actually a tool (http://root.cern.ch/) used for on the fly variable manipulation. I am not sure how to install this framework.
  5. May 15, 2007 #4
    If you've installed XCode then the dev tools should be installed too becuase XCode uses gcc for compilation.

    Regarding ROOT (as opposed to the superuser account), never heard of it.
  6. May 17, 2007 #5
    ROOT is used extensively in nuclear physics, at least from what I gather. I know that it is used by everyone working on the STAR experiment, which is what my project for the summer is related to.
  7. Oct 17, 2009 #6
    ROOT is the name commonly used for the primary account (the one with all administrative power) on many Unix based systems. When you are logged into a non-root account and try to do something that required special permission you often use the superuser command. If you were logged in as root you would not need to use the superuser command.
  8. Oct 17, 2009 #7


    User Avatar

    Staff: Mentor

    Under Mac OS you never need to log on as 'root' directly. Accounts with administrative privileges can perform Unix-style tasks that require root privileges by using 'sudo [command]' (to run one command at at time) or 'sudo -s' (to launch a shell that has root privileges).
  9. Oct 17, 2009 #8
    You can also use sudo !! if you entered a command that requires permission and you do not want to reenter the command. The "!!" simply does the last command, so in effect you execute the previously submitted command with sudo privileges.
  10. Oct 17, 2009 #9
    Which is lovely and all, but has little or nothing to do with this thread. The OP was talking about this root, not anything to do with user levels.
  11. Oct 18, 2009 #10
    For a beginner, XCode could be a bit overwhelming. For simple programs (using only 1-3 files) I prefer using Textmate & GCC. Although it doesn't have auto-completion it has syntax highlighting and amazing keyboard shortcuts. It's a shareware, but you can try it for free for a month, and it's definitely worth it!

    As far as GCC is concerned, you'll have it installed as long as you install the dev tools from your OS X dvd. It's really easy to use and the man pages ("man gcc") have a lot of useful information.

  12. Oct 18, 2009 #11
  13. Oct 18, 2009 #12
  14. Oct 19, 2009 #13
    If you have put the code for a C++ program into the file "somefile.cpp", you can compile and run this quickly without using xcode by typing:

    g++ somefile.cpp -o somefile

    This will be enough to get "hello world" running. You will need to have xcode installed or this will not work, however.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook