LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-03-2010, 06:51 PM   #1
donaldfarkas
LQ Newbie
 
Registered: Sep 2010
Posts: 18

Rep: Reputation: 0
NOOBIE C++ Question


Code:
#include <iostream>


int main()
{

	int number1;
     	int number2;
	int sum;
	
	std::cout << "Enter first integer: ";
	std::cin >> number1;
		
	std::cout << "Enter second integer: ";
	std::cin >> number2;

	sum = number1 + number2;

	std::cout << "Sum is " << sum << std::end1;
	
	return 0;

}
im going by the book and im having some issues here it wont compile successfully the error is:
Code:
[Donald@localhost ~]$ cd Desktop/C++
[Donald@localhost C++]$ make addition
make: *** No rule to make target `addition'.  Stop.
 
Old 09-03-2010, 06:53 PM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,808

Rep: Reputation: 604Reputation: 604Reputation: 604Reputation: 604Reputation: 604Reputation: 604
Do you even have a Makefile created in ~/C++ ?
 
Old 09-03-2010, 07:02 PM   #3
donaldfarkas
LQ Newbie
 
Registered: Sep 2010
Posts: 18

Original Poster
Rep: Reputation: 0
no it did not create a executable
 
Old 09-03-2010, 07:31 PM   #4
alan99
Member
 
Registered: Mar 2010
Distribution: Debian
Posts: 180

Rep: Reputation: 31
A makefile is a kind of a template. It tells gcc how to build a application. It tells gcc what kind of command line options to use, what kind of objects to compile, and other things such as where to look for headers files and shared libraries. If you don't want to bother to learn 'make' you can do as many do, install an IDE such as Eclipse. That is what I did.
 
Old 09-03-2010, 07:38 PM   #5
donaldfarkas
LQ Newbie
 
Registered: Sep 2010
Posts: 18

Original Poster
Rep: Reputation: 0
a make file? i didnt use it for my previous program to compile why do i need it now? they are just console programs
 
Old 09-03-2010, 07:55 PM   #6
alan99
Member
 
Registered: Mar 2010
Distribution: Debian
Posts: 180

Rep: Reputation: 31
You don't really have to have one (it makes it easier if you have a lot of objects that are being compiled and linked into the final program) if you are just compiling one source file, you can use g++ on the comand line if you use the right options.
 
Old 09-03-2010, 07:59 PM   #7
alan99
Member
 
Registered: Mar 2010
Distribution: Debian
Posts: 180

Rep: Reputation: 31
By the way, I compiled your program and it had an error in it. I'll let you figure out what it is when you get it to compile. That the 'fun' part of learning to program.
 
Old 09-03-2010, 08:09 PM   #8
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,808

Rep: Reputation: 604Reputation: 604Reputation: 604Reputation: 604Reputation: 604Reputation: 604
So, why are you running make?
 
Old 09-03-2010, 09:12 PM   #9
donaldfarkas
LQ Newbie
 
Registered: Sep 2010
Posts: 18

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by alan99 View Post
By the way, I compiled your program and it had an error in it. I'll let you figure out what it is when you get it to compile. That the 'fun' part of learning to program.
yea ifound it to endl it was a 1 instead of the L but still did not fix my problem i think something is wrong with my compiler
 
Old 09-03-2010, 09:25 PM   #10
crosstalk
Member
 
Registered: Jul 2010
Distribution: Gentoo, Debian, Mint, Xubuntu
Posts: 150

Rep: Reputation: 35
When you run "make", it tries to read a file (called a makefile, usually named "Makefile"). This file contains information on how to compile a program.

Since you have no Makefile, make does not know how to compile the program. You could either do it manually, with g++, or you can write a Makefile (there's also cmake, autotools, and several other pieces of software I don't know how to use.)

"g++" is the C++ compiler. You can invoke it to compile this program with:
Code:
g++ addition.cpp -o addition
This will produce this program as an executable.

A makefile contains targets. For example, to compile a program named "main" from the file "main.cpp", you could add as a rule (make is picky on tabs vs. spaces):
Code:
main: main.cpp
<tab>g++ main.cpp -o main
Most makefiles start (i.e. it must be first) with the target "all", as a convention:
Code:
all: main
and include a "clean" target:
Code:
clean:
<tab>rm -f main
You could compile by hand, with g++, or you could read up on Makefiles. I hope this has enough information for you to write a makefile for this program.

And, as alan99 said, there is an error in the program. You'll figure it out.

Post any issues you have if you try to write a Makefile for this project.

EDIT: you found the error with "end1" vs "endl"

Last edited by crosstalk; 09-03-2010 at 09:26 PM. Reason: Too slow
 
Old 09-03-2010, 11:07 PM   #11
donaldfarkas
LQ Newbie
 
Registered: Sep 2010
Posts: 18

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by crosstalk View Post
When you run "make", it tries to read a file (called a makefile, usually named "Makefile"). This file contains information on how to compile a program.

Since you have no Makefile, make does not know how to compile the program. You could either do it manually, with g++, or you can write a Makefile (there's also cmake, autotools, and several other pieces of software I don't know how to use.)

"g++" is the C++ compiler. You can invoke it to compile this program with:
Code:
g++ addition.cpp -o addition
This will produce this program as an executable.

A makefile contains targets. For example, to compile a program named "main" from the file "main.cpp", you could add as a rule (make is picky on tabs vs. spaces):
Code:
main: main.cpp
<tab>g++ main.cpp -o main
Most makefiles start (i.e. it must be first) with the target "all", as a convention:
Code:
all: main
and include a "clean" target:
Code:
clean:
<tab>rm -f main
You could compile by hand, with g++, or you could read up on Makefiles. I hope this has enough information for you to write a makefile for this program.

And, as alan99 said, there is an error in the program. You'll figure it out.

Post any issues you have if you try to write a Makefile for this project.

EDIT: you found the error with "end1" vs "endl"

Thank you so much for your time for writing all this up!!! So your saying if i want to by-pass these problems i can just use
Code:
g++ addition.cpp -o addition
while my programs are quite simple. and when i get into more complex programs then i might have to use a makefile.
 
Old 09-03-2010, 11:11 PM   #12
Kenny_Strawn
Senior Member
 
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Blog Entries: 62

Rep: Reputation: 56
If you need to compile the C++ file, just use g++ if it's one file, like so:

Code:
$ g++ -Wall -Wextra -o addition addition.cpp
 
Old 09-03-2010, 11:16 PM   #13
crosstalk
Member
 
Registered: Jul 2010
Distribution: Gentoo, Debian, Mint, Xubuntu
Posts: 150

Rep: Reputation: 35
Quote:
Originally Posted by donaldfarkas View Post
So your saying if i want to by-pass these problems i can just use
Code:
g++ addition.cpp -o addition
while my programs are quite simple. and when i get into more complex programs then i might have to use a makefile.
That is correct, although you (almost) never have to use a makefile (make is just used for convenience.) Just remember -- many programs have hundreds of source files, and running "g++" (and any other pieces of software, such as a linker) on all of them would be quite tiresome without make.

Glad I could help. Good luck learning C++.

Last edited by crosstalk; 09-03-2010 at 11:17 PM. Reason: clarification
 
Old 09-04-2010, 07:48 AM   #14
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
Also, make compiles only the files that changed, saving time for big multi-file projects.
 
Old 09-04-2010, 09:28 AM   #15
donaldfarkas
LQ Newbie
 
Registered: Sep 2010
Posts: 18

Original Poster
Rep: Reputation: 0
[Donald@localhost ~]$ cd Desktop/C++
[Donald@localhost C++]$ ls
addition.cpp printingLineofText
[Donald@localhost C++]$ g++ addition.cpp -o addition
g++: addition.cpp: No such file or directory
g++: no input files
[Donald@localhost C++]$ ^C
[Donald@localhost C++]$

so above paste shows that i have navigated to the right directory and showing that the file is thereand then i try to compile and shows no such file
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
DNS Question from Noobie terrytibbs Linux - Networking 11 07-25-2009 12:30 PM
Noobie rpm question itz2000 Linux - Newbie 4 08-31-2007 07:37 PM
smart noobie question alaios SUSE / openSUSE 1 10-27-2006 11:03 AM
noobie up2date question zarnold Red Hat 3 09-02-2006 11:10 PM
noobie question about rc.d file bob cashman Ubuntu 3 07-15-2005 11:31 AM


All times are GMT -5. The time now is 10:28 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration