how to make a c++ program and compile it on macbook pro

how to make a c++ program and compile it on macbook pro


i have no idea how to do it i am a new user

MacBook Pro with Retina display, OS X Yosemite (10.10.2), null

Posted on Sep 5, 2015 1:58 PM

Reply
8 replies

Jul 2, 2017 1:07 PM in response to shreyanshfromjodhpur

First You Open a Terminal window and at the prompt type g++ ( $> g++ ) press Enter if it is Not install it will tell

you that you need some developer tools and tell you how to install them.. If it Is Install it will say something like

No Filename given.


to compile C++ Program:

1.> Write you C++ Program ( ie. Some.cpp )

2.> at the Prompt $:> g++ ./Some.cpp -o ./MyProg -or- $:>g++ ./Some.cpp


NOTE:

$:> g++ ./Some.cpp -o ./MyProg ---> Makes a Executable file Named MyProg

You can use any filename you want to, I Use MyProg for this example.

$:> g++ ./Some.cpp ---> Make a standard Executable called --> a.out

If you need a more secure error correct version of an Executable (ie. No warning error.)

Then use the -Wall Option: $:>g++ -Wall ./Some.cpp -o ./MyProg


PS:

You can use VI or any other Unix Command Line Text Editor to Write your C++.cpp File.

like: vi, vim, elvis, ed, pico, nano, mcedit, joe, jed, emacs ... Or Whatever you want, But

it has to be a straight Text Editor.!! *** No Word Processors.!! *** like: word or works or

Anything with different Fonts or layouts.!! Write All your Programs in Just plain Text Editors.


I Hope That This Has Helped You.. Good Luck and God bless you:

But Most of all Have Fun Programming..



*^*(:)<[?]>(:)*^*

Michael L. Estes

(31337 - #!/bin )


## [End of File.]

Sep 5, 2015 2:12 PM in response to shreyanshfromjodhpur

I'm not so sure that is possible. Xcode which can be downloaded for free from the App Store, allows you to program in Objective C or Swift. I thought I read that visual studio (Microsoft's) development package is now available on OS X but I'm not sure. You are going to need to look for something that will run on OS X. Does it have to be c++? Objective C is similar but object oriented.


You might also want to look into Parallels (virtual machine software) this will allow you to run windows or another distribution of linux as a virtual machine and then you would have more IDEs to choose from.

Sep 6, 2015 7:31 AM in response to shreyanshfromjodhpur

Make certain that your Mac is running OS X 10.10.5, not the 10.10.2 that you show in your signature. Sign up for a free Apple Developer account and not the paid version at this time. Once you are signed up for that free developer account, you will want to download/install the latest (non-beta) Command Line Tools (OS X 10.10) for Xcode 6.3.2. This gives you command line compilation tools (C/C++/Objective-C), their libraries, and include files for development in the Terminal. It does not include Xcode 6.3.2 — which you don't need initially for learning to make and compile a C++ program. Apple does not provide the GNU compiler technology, and instead, implements them more efficient, modern Clang/LLVM solution.


Here is a typical Clang C++ compilation syntax that does not use any of the C++ 11 extensions:

clang++ -Wall -O2 -o fib_memo fib_memo.C -stdlib=libc++

Sep 6, 2015 10:49 PM in response to shreyanshfromjodhpur

You need to install the Mac Developer Tools either from your original Mac OS X disk or by downloading the latest version. This package includes the GCC compiler collection (supporting the C and C++ languages, amongst others).


  • Open xCode by finding it in the Applications window on your Macintosh. Your first duty will be to create a new project. Do this by choosing "New Project" from the "File" menu! An "Assistant" window should open that allows you to create the project (see below). You should select "Tools -> C++ Tool" to create the project.Java training in chennai
    User uploaded file
  • Next, you need to create a project. In our example below, we have given it the name "myProject". The default path "~/myProject/" appears. You can change this, but it makes sense to use the default.
  • User uploaded file

  • In the "myProject" window, you will see that a program named "main.cpp" has been created and installed in the project by default. (Sometimes these wizards are a little too helpful, if you know what I mean.) This program almost certainly does not do what you want it to do, but it is a fully-functioning C++ program. This means you can compile and run it right now. Go ahead, if you must. We'll wait for you to get it out of your system. Corporate training in chennai
  • User uploaded file

  • When you are ready to get down to business, you should select File->Save As... and give this file another name. In our example, that name is "myProgram.cpp". We can actually think of much more clever names, but are resisting the impulse.
  • User uploaded file

  • Notice that after saving the program with a new name, the new program is installed in your project, and "main.cpp" is pretty much forgotten. This stands in contrast to Microsoft Visual C++, which keeps main.cpp in your program even after you decided to get rid of it.
  • User uploaded file

  • What now? How about editing myProgram.cpp so that it contains a working C++ program. We know you will find the urge to write a "Hello, World!" program irresistible. A variant appears in the example below.
  • User uploaded file

  • Notice the icons in the toolbar that say "Build", and "Build and Go". The simplicity of this interface makes one wonder what all the other compiler designers are thinking. In case it is not obvious, clicking the "Build" icon will build the project -- that is, it will compile the program file(s) and link the code for any other included libraries, producing an executable ("double-clickable") file. Clicking the "Build and Go" icon will not only build the project, but run the program! Notice that in the window that appears, you also have access to various debugging tools. These are fairly self-explanatory. In the figure shown below, the sample program has been executed, the user has entered data when prompted, and output has been produced. The output can be saved in a file by selecting "Save" from the "File" menu.
  • User uploaded file

    Nov 17, 2015 3:39 AM in response to shreyanshfromjodhpur

    I appreciate the question because I had the same question! I know Stack Overflow hates these questions but I've never coded C++ on my Macbook.

    You need to install the Mac Developer Tools either from your original Mac OS X disk or by downloading the latest version. This package includes the GCC compiler collection (supporting the C and C++ languages, amongst others).

    Basically you should get a (free) developer account and then download Xcode.

    Unfortunately, starting with Xcode 4, Apple is charging 5$ for the download. So you could either decide to pay this, or download the previous version (Xcode 3)The main page for Xcode is this. There you will find links to Xcode 4 and Xcode 3 (search within the page)


    Follow the instructions carefully.


    • Download Xcode
    • Install Xcode
    • Starting a New Project
    • Coding Compiling and Running


    This tutorial is to help out anyone that wants to create a terminal based c++ program using Xcode for Mac OS X and for the persons who are into Java training in chennai. This is mainly for the people in CS 150 at ODU, but I think many can benefit from this as a getting started guide. If you know some basic C++ already this guide will be easier to you, but no prior knowledge is required for this how-to.

    Nov 19, 2015 3:11 AM in response to shreyanshfromjodhpur

    Make SURE you convert to plain text in TextEdit when writing code. Compilers and rich text format don't get along.

    You'll need a C++ compiler, obviously - and it needs to be in your PATH environment variable to be usable in the Terminal. If you use Xcode's command line tools, this part is done for you.

    Compiling and running is really easy:

    1. compiler_name options program_name.ext
    2. ./program_name

    ...where the compiler_name and options depend on your compiler.


    For Xcode, either GCC or Clang will work.

    Are your projects 10s,100s,1000s,10000s,etc. lines of code? I've worked on professional projects with millions of lines of code, and we used vi/vim to edit and make/rake to build. My point is that you're complaining that the tools youve found aren't just perfect for you to ply your trade. I encourage you to stop that sort of thinking. It will serve you well to be comfortable with a wide range of tools, so you can be effective in lots of environments.

    You've stated Eclipse is too complex and a text editor and gcc is too simple. You're basically saying: without Borland I'm not comfortable programming. I would insist you work through that discomfort and come out the other side a more versatile programmer. If you don't want anything different, you can get a Windows VM and install Borland. You'd be robbing yourself of an opportunity to learn and grow if you do, though.(hadoop training in chennai)


    Code more, search for a Borland-alike less. Good luck.


    -Lee


    P.S. unless you invent a language and code in it for years, don't say you're advanced. It's a death sentence, and makes the offer to others to attack your understanding.

    This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

    how to make a c++ program and compile it on macbook pro

    Welcome to Apple Support Community
    A forum where Apple customers help each other with their products. Get started with your Apple Account.