How to Compile CPP in a Mac

Apple's Xcode integrated developer environment includes the GNU compiler. It works to compile source codes in a variety of languages, including C++. Linux and Unix programmers will find the command line compiler familiar. Apple's version of the GNU compiler supports standard C++ to let experienced or novice programmers get started without learning any new keywords for simple programs. At the time of publication, Xcode is available for free from Apple's Developer website.

Instructions

    • 1

      Open your preferred Web browser and go to the developer.apple.com/programs/register website to create a free Apple Developer account. Click "Get Started" and fill out the information to create your account. Check your email at the end of the process and click on the confirmation link in the email provided.

    • 2

      Go to developer.apple.com/xcode/ and log in using your Apple Developer ID to download Xcode. Double-click the Xcode DMG file to open it. Double-click the "Xcode and iOS SDK.mpkg" file to begin the installation

    • 3

      Follow the prompts to install Xcode. Make sure to click the check box to install the "UNIX Development" tools. Restart your Mac once the installation is complete.

    • 4

      Click the "Finder" icon in the Dock. Click the "Utilities" option in the Go menu. Double-click on the "Terminal" app.

    • 5

      Type "cd /Users/myuser/cppsource" without the quotes and press "Enter." Replace "myuser/cppsource" with the folder containing your C++ source files.

    • 6

      Type "gcc -o program sourcecode.cc" without the quotes and press "Enter." Replace "sourcecode.cc" with the name of your source code file, and "program" with the name you want to assign the compiled program.

    • 7

      Wait for the program to finish compiling. Type "./program" without the quotes and press "Enter" to test your program. Replace "program" with the name of your program.

Tips & Warnings

  • The "gcc" command provides many options, type "man gcc" at the command line and press "Enter" to see a complete list.

Related Searches:

References

Resources

Comments

Related Ads

Featured