Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 20, 2011, 06:31 AM   #1
gmcguinn
macrumors newbie
 
Join Date: Jan 2011
Location: Dublin, Ireland
:( complete programming noob! (C++)

Hey guys,

Well from what you can see in the title I am completely new to C++ programming. I have just started it in college and am really enjoying it.
However I wanted to set up all the software on my MBP so that I could work on it.

In college we write the code on a program called Smultron, save it as a .cpp file and then go to terminal to run it.

Now here comes my problem.... I have downloaded Smultron for my laptop and I have written a quick "ºC -> ºF conversion program". When I try to set that up in Terminal by using the command that we were told to use ("make program1") I get this error message in return...

"make: *** No rule to make target `practical1'. Stop."


This error doesn't come up in college. What I get in college is something like "g++ ........." and then I put in something like "./practical1"

As I have said before I want to try and work on my programming at home so I would love for some of your help.

Don't forget that I am a complete noob so try and keep it simple! We all start somewhere!
gmcguinn is offline   0 Reply With Quote
Old Jan 20, 2011, 06:43 AM   #2
robbieduncan
Demi-God (Moderator)
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
make requires a Makefile to work. I suggest you copy the one from college.
robbieduncan is offline   0 Reply With Quote
Old Jan 20, 2011, 06:47 AM   #3
Bill McEnaney
macrumors 6502
 
Join Date: Apr 2010
Quote:
Originally Posted by gmcguinn View Post
Hey guys,

Well from what you can see in the title I am completely new to C++ programming. I have just started it in college and am really enjoying it.
However I wanted to set up all the software on my MBP so that I could work on it.

In college we write the code on a program called Smultron, save it as a .cpp file and then go to terminal to run it.

Now here comes my problem.... I have downloaded Smultron for my laptop and I have written a quick "ºC -> ºF conversion program". When I try to set that up in Terminal by using the command that we were told to use ("make program1") I get this error message in return...

"make: *** No rule to make target `practical1'. Stop."


This error doesn't come up in college. What I get in college is something like "g++ ........." and then I put in something like "./practical1"

As I have said before I want to try and work on my programming at home so I would love for some of your help.

Don't forget that I am a complete noob so try and keep it simple! We all start somewhere!
You don't need the "make" command if your program is only a few lines long. If it just converts degrees fahrenheit to degrees celsius, you probably can compile it with, say, this command:
Code:
g++ practice1.cpp -o practice1
. That command tells the computer to compile your program with the C++ compiler and to call the executable program "practice1." If the machine finds mistakes, typos, in your program, the machine won't create the executable program. To make it create one, you'll need to correct the mistakes and recompile the program with the command I wrote in the code box.

You usually need the "make" command when you want to compile a big program composed of many separately-compiled functions.

Last edited by Bill McEnaney; Jan 20, 2011 at 07:01 AM.
Bill McEnaney is offline   0 Reply With Quote
Old Jan 20, 2011, 07:28 AM   #4
gmcguinn
Thread Starter
macrumors newbie
 
Join Date: Jan 2011
Location: Dublin, Ireland
Quote:
Originally Posted by robbieduncan View Post
make requires a Makefile to work. I suggest you copy the one from college.
Ok and where do I find that file and what will it look like?
gmcguinn is offline   0 Reply With Quote
Old Jan 20, 2011, 07:29 AM   #5
robbieduncan
Demi-God (Moderator)
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Quote:
Originally Posted by gmcguinn View Post
Ok and where do I find that file and what will it look like?
It'll be a file called "Makefile". Normally it'd be in the same directory as the code, but depending on their setup it could be anywhere. I'd ask your lecturer.

Or, as suggested above, do without it.
robbieduncan is offline   0 Reply With Quote
Old Jan 20, 2011, 07:47 AM   #6
mydogisbox
macrumors member
 
Join Date: Jan 2011
How to make a makefile

Quote:
Originally Posted by gmcguinn View Post
Ok and where do I find that file and what will it look like?
http://www.eng.hawaii.edu/Tutor/Make/

You can just make your own makefile. If you are going to be doing more command-line programming, it would be a good idea to learn how to do so anyway.
mydogisbox is offline   0 Reply With Quote
Old Jan 20, 2011, 07:50 AM   #7
gmcguinn
Thread Starter
macrumors newbie
 
Join Date: Jan 2011
Location: Dublin, Ireland
Quote:
Originally Posted by mydogisbox View Post
http://www.eng.hawaii.edu/Tutor/Make/

You can just make your own makefile. If you are going to be doing more command-line programming, it would be a good idea to learn how to do so anyway.
Ahh ok thanks... And it doesn't matter what text editor I am using? It will work fine with Smultron.
gmcguinn is offline   0 Reply With Quote
Old Jan 20, 2011, 07:50 AM   #8
gmcguinn
Thread Starter
macrumors newbie
 
Join Date: Jan 2011
Location: Dublin, Ireland
Quote:
Originally Posted by robbieduncan View Post
It'll be a file called "Makefile". Normally it'd be in the same directory as the code, but depending on their setup it could be anywhere. I'd ask your lecturer.

Or, as suggested above, do without it.
Ok and say I go in and get it to a usb where is the best place to store it and how do I set it up?
gmcguinn is offline   0 Reply With Quote
Old Jan 20, 2011, 07:51 AM   #9
balamw
Demi-God (Moderator)
 
balamw's Avatar
 
Join Date: Aug 2005
Location: New England, USA
First things first.

Do you have gcc/g++ installed on your Mac?

The easiest way to get it is to install the Developer Tools (including Xcode) from the Optional Installs disc shipped with your Mac.

B
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme
balamw is online now   0 Reply With Quote
Old Jan 20, 2011, 07:56 AM   #10
robbieduncan
Demi-God (Moderator)
 
robbieduncan's Avatar
 
Join Date: Jul 2002
Location: London
Quote:
Originally Posted by gmcguinn View Post
Ok and say I go in and get it to a usb where is the best place to store it and how do I set it up?
make will automatically look for a file called Makefile in the cwd. In all honesty instead of expecting to be spoon-fed every minor you should be doing your own research when pointed in the right direction. Before even asking the question at the top of this thread you should have read the manpage for make which would have told you the answer. Any programmer worth anything relies on being able to use the documentation for the tools, languages and APIs. Start building this critical core skill early.
robbieduncan is offline   0 Reply With Quote
Old Jan 20, 2011, 08:01 AM   #11
balamw
Demi-God (Moderator)
 
balamw's Avatar
 
Join Date: Aug 2005
Location: New England, USA
Ah the joy of IDEs and editors that hide the inner workings from you. (There was a recent thread that had some resources to cure you of this, will link here). EDIT: http://forums.macrumors.com/showthread.php?t=1078777 read lee1210's posts #4 and #13 in particular.

Another issue here is that at school it sounds like Smultron is calling g++, while it is trying to call make at home. EDIT: This may be a configuration issue with Smultron or just the fact that g++ is missing. Make sure you can get the instructions in lee1210's post #4 linked above to work.

B
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme

Last edited by balamw; Jan 20, 2011 at 08:07 AM.
balamw is online now   0 Reply With Quote
Old Jan 20, 2011, 11:54 AM   #12
chown33
macrumors 601
 
Join Date: Aug 2009
Make doesn't always require a makefile. It has built-in rules (implicit rules) for making simple targets.

If I go to a directory that contains a file "handy.cpp" and I type:
Code:
make handy
it will run the command:
Code:
g++     handy.cpp   -o handy
You can watch it evaluate implicit rules with this command instead:
Code:
make -d handy
It'll output a pretty long list, of which the last few lines are most relevant.
chown33 is offline   0 Reply With Quote
Old Jan 20, 2011, 12:16 PM   #13
gmcguinn
Thread Starter
macrumors newbie
 
Join Date: Jan 2011
Location: Dublin, Ireland
Quote:
Originally Posted by balamw View Post
First things first.

Do you have gcc/g++ installed on your Mac?

The easiest way to get it is to install the Developer Tools (including Xcode) from the Optional Installs disc shipped with your Mac.

B
I have installed xCode but how do I install g++?
gmcguinn is offline   0 Reply With Quote
Old Jan 20, 2011, 12:24 PM   #14
balamw
Demi-God (Moderator)
 
balamw's Avatar
 
Join Date: Aug 2005
Location: New England, USA
Quote:
Originally Posted by gmcguinn View Post
I have installed xCode but how do I install g++?
Comes with. If you installed Xcode with the default settings, you have g++.

B
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme
balamw is online now   0 Reply With Quote
Old Jan 20, 2011, 12:25 PM   #15
subsonix
macrumors 68000
 
Join Date: Feb 2008
Quote:
Originally Posted by gmcguinn View Post
I have installed xCode but how do I install g++?
You don't need to, it's just a GCC, C++ front end.
subsonix is offline   0 Reply With Quote
Old Jan 20, 2011, 12:28 PM   #16
gmcguinn
Thread Starter
macrumors newbie
 
Join Date: Jan 2011
Location: Dublin, Ireland
[QUOTE=chown33;11760143]
it will run the command:
Code:
g++     handy.cpp   -o handy
I tried to run your suggestion in terminal and I got :
"i686-apple-darwin10-g++-4.2.1: practical1.cpp: No such file or directory
i686-apple-darwin10-g++-4.2.1: no input files
"
gmcguinn is offline   0 Reply With Quote
Old Jan 20, 2011, 12:30 PM   #17
gmcguinn
Thread Starter
macrumors newbie
 
Join Date: Jan 2011
Location: Dublin, Ireland
Quote:
Originally Posted by balamw View Post
Comes with. If you installed Xcode with the default settings, you have g++.

B
I'm confused now!

I will try those tasks that you supplied from the other forum and i'll get back to you all.
gmcguinn is offline   0 Reply With Quote
Old Jan 20, 2011, 12:31 PM   #18
subsonix
macrumors 68000
 
Join Date: Feb 2008
Are you in the folder where practical1.cpp is located? Did you spell it right etc?

Edit: The error message you get is from g++, the complaint is that g++ can't find the file practical.cpp in the current folder.
subsonix is offline   0 Reply With Quote
Old Jan 20, 2011, 12:41 PM   #19
gmcguinn
Thread Starter
macrumors newbie
 
Join Date: Jan 2011
Location: Dublin, Ireland
Quote:
Originally Posted by balamw View Post
Ah the joy of IDEs and editors that hide the inner workings from you. (There was a recent thread that had some resources to cure you of this, will link here). EDIT: http://forums.macrumors.com/showthread.php?t=1078777 read lee1210's posts #4 and #13 in particular.

Another issue here is that at school it sounds like Smultron is calling g++, while it is trying to call make at home. EDIT: This may be a configuration issue with Smultron or just the fact that g++ is missing. Make sure you can get the instructions in lee1210's post #4 linked above to work.

B
Ok I typed in ...

echo "#include <stdio.h>
int main(int argc, char *argv[]) {
printf(\"Hello, World.\\n\");
return 0;
}" > myHello.c
gcc myHello.c
./a.out


... to terminal and it worked so what should I do next?
gmcguinn is offline   0 Reply With Quote
Old Jan 20, 2011, 12:43 PM   #20
gmcguinn
Thread Starter
macrumors newbie
 
Join Date: Jan 2011
Location: Dublin, Ireland
Quote:
Originally Posted by subsonix View Post
Are you in the folder where practical1.cpp is located? Did you spell it right etc?

Edit: The error message you get is from g++, the complaint is that g++ can't find the file practical.cpp in the current folder.
I have the practical1.cpp file on my desktop and I am trying to use terminal to run it... That is how we were shown to do it in the lecture. We were told to go into terminal and type "make practical1" and then "./practical1"
gmcguinn is offline   0 Reply With Quote
Old Jan 20, 2011, 12:46 PM   #21
subsonix
macrumors 68000
 
Join Date: Feb 2008
Quote:
Originally Posted by gmcguinn View Post
I have the practical1.cpp file on my desktop and I am trying to use terminal to run it... That is how we were shown to do it in the lecture. We were told to go into terminal and type "make practical1" and then "./practical1"
Don't use make, if you have no make script. Make is meant for situations where you have multiple source files.

try this:

Code:
cat > hello.cpp << eof
> #include <iostream>
> 
> int main()
> {
> std::cout << "Hello, world\n";
> return 0;
> }
Hit: ctrl -d

type: g++ hello.cpp -o hello

then: ./hello


There, your first c++ program.
subsonix is offline   0 Reply With Quote
Old Jan 20, 2011, 12:47 PM   #22
ulbador
macrumors 68000
 
ulbador's Avatar
 
Join Date: Feb 2010
Quote:
Originally Posted by chown33 View Post
Make doesn't always require a makefile. It has built-in rules (implicit rules) for making simple targets.
Well that's neat... you learn something new every day...
__________________
Mooooooooooooo
ulbador is offline   0 Reply With Quote
Old Jan 20, 2011, 12:47 PM   #23
chown33
macrumors 601
 
Join Date: Aug 2009
Quote:
Originally Posted by gmcguinn View Post
I tried to run your suggestion in terminal and I got :
"i686-apple-darwin10-g++-4.2.1: practical1.cpp: No such file or directory
i686-apple-darwin10-g++-4.2.1: no input files
"
Please provide more information. In the same directory where you typed the make command line, enter this command and post the output:
Code:
pwd; ls -l
We need to see exactly what context make is trying to use. Since that context is all the files in the current working directory, we need to see the actual list of files.


I wonder about the accuracy of your posts. For example, in your original post you wrote:
Quote:
When I try to set that up in Terminal by using the command that we were told to use ("make program1") I get this error message in return...

"make: *** No rule to make target `practical1'. Stop."
I've added red and blue colors to hilite the inconsistency. program1 and practical1 are not the same thing.

You can copy from the Terminal window and paste into posts. You can also copy from other windows and paste into Terminal. I suggest that you edit command-lines in a text editor, then copy and paste them into Terminal. When something doesn't work, copy and paste the entire command-line and its output into a post.
chown33 is offline   0 Reply With Quote
Old Jan 20, 2011, 12:49 PM   #24
balamw
Demi-God (Moderator)
 
balamw's Avatar
 
Join Date: Aug 2005
Location: New England, USA
Great. We know for sure you have a compiler now.

Quote:
Originally Posted by gmcguinn View Post
I have the practical1.cpp file on my desktop and I am trying to use terminal to run it... That is how we were shown to do it in the lecture. We were told to go into terminal and type "make practical1" and then "./practical1"
What happens now if you try that?

If you need to substitute

Code:
g++ -o practical1 practical1.cpp
for
Code:
make practical1
B
__________________
MBA (13" 1.7 GHz 128GB), UMBP (15" SD 2.8 GHz), UMB (13" 2.4 GHz), iMac (17" Yonah), 32GB iPad 3 WiFi+LTE, 64 GB iPad WiFi, 32 GB iPhone 5, Airport Extreme
balamw is online now   0 Reply With Quote
Old Jan 20, 2011, 12:55 PM   #25
gmcguinn
Thread Starter
macrumors newbie
 
Join Date: Jan 2011
Location: Dublin, Ireland
Quote:
Originally Posted by balamw View Post
Great. We know for sure you have a compiler now.



What happens now if you try that?

If you need to substitute

Code:
g++ -o practical1 practical1.cpp
for
Code:
make practical1
B
Here is my terminal output for make practcal1 and the replacement that you provided.....


Code:
Gavin-McGuinnesss-MacBook-Pro:~ Gav$ make practical1
make: *** No rule to make target `practical1'.  Stop.
Gavin-McGuinnesss-MacBook-Pro:~ Gav$ g++ -o practical1 practical1.cpp
i686-apple-darwin10-g++-4.2.1: practical1.cpp: No such file or directory
i686-apple-darwin10-g++-4.2.1: no input files
Gavin-McGuinnesss-MacBook-Pro:~ Gav$
gmcguinn is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
Help With Structures and Classes (C++) ghall Mac Programming 13 Dec 13, 2007 03:49 PM
what's wrong?! (c++) chris200x9 Mac Programming 3 Oct 31, 2007 07:59 PM
Computer Science class (C++) svail11 Mac Programming 5 Sep 24, 2006 05:53 PM
How do you use strings (c++) with xCode rgwebb Mac Programming 2 Nov 28, 2005 10:29 AM
Coding conundrum (C++) GeeYouEye Mac Help/Tips 2 May 17, 2003 01:48 AM


All times are GMT -5. The time now is 03:21 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC