Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

gmcguinn

macrumors newbie
Original poster
Jan 20, 2011
28
0
Dublin, Ireland
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! :)
 
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:
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.
 
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?
 
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
 
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.
 
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: https://forums.macrumors.com/threads/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
 
Last edited:
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.
 
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++?
 
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.
 
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: https://forums.macrumors.com/threads/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?
 
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"
 
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.
 
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:
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.
 
Great. We know for sure you have a compiler now.

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
 
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$
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.