LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-10-2012, 01:53 PM   #1
fazc99
LQ Newbie
 
Registered: Jan 2012
Posts: 4

Rep: Reputation: Disabled
I can't run my programmes


I can't run my programmes in c++ I think it is a hardware issue because when i click on run nothing at all happens so i think that as my computer is very old and pentium 4 I would like to know if it is me doing something wrong or my hardware. I compose a c++ document into Documents then i save it as .cpp and i right click on it and select open and then run nothing happens if anyone knows the route of my problem please reply.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 02-10-2012, 02:22 PM   #2
ButterflyMelissa
Senior Member
 
Registered: Nov 2007
Location: Somewhere on my hard drive...
Distribution: Manjaro
Posts: 2,766
Blog Entries: 23

Rep: Reputation: 411Reputation: 411Reputation: 411Reputation: 411Reputation: 411
Did you compile the cpp files?
The roadmap is simple - create a text file, store if (indeed) as cpp file and compile it. Then, the result can be started up.

Maybe this could help:

Quote:
gcc <program.cpp>
Good luck

Thor

Last edited by ButterflyMelissa; 02-10-2012 at 02:27 PM.
 
2 members found this post helpful.
Old 02-10-2012, 04:03 PM   #3
fazc99
LQ Newbie
 
Registered: Jan 2012
Posts: 4

Original Poster
Rep: Reputation: Disabled
I read your blog and iknow you do java but do you know any half descent c++ compilers because i can't find one?
 
Old 02-10-2012, 04:39 PM   #4
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
Step-by-step first c++ program compile and run.

1. Open a text editor
2. Write your code. For instance:
Code:
#include <iostream>

int main( void ) {
  std::cout << "Hello World!" << std::endl;

  return 0;
}
3. Save your code--make note of the directory you saved it in (usually something like /home/username/Documents or /home/username/Projects)
4. Open a terminal (depending on your desktop environment, this could be named GNOMETerm, Konsole, Xterm, etc.)
5. In the new terminal window opened, change to the directory that contains your saved code (e.g. "cd /home/username/Documents")
6. Type the following command:
Code:
g++ -o executable_name source_code_filename
7. Open your code and correct any error identified by the compiler and save.
8. Repeat steps #6 and #7 until you receive no errors.
9. Run your program by typing (note: do not omit the leading './'):
Code:
./executable_name
Substitute whatever you want to name your program for executable_name.

Substitute the name of your saved code file for source_code_filename.

If you receive a "command not found" error message when you try step #6, you need to install a c++ compiler.

For Debian (as root): "apt-get install g++"
For Ubuntu: "sudo apt-get install g++"
For RedHat based distros: "yum install gcc-c++"

Last edited by Dark_Helmet; 02-10-2012 at 04:49 PM.
 
1 members found this post helpful.
Old 02-10-2012, 06:59 PM   #5
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,599
Blog Entries: 4

Rep: Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905Reputation: 3905
I would like to draw your attention specifically to the comment in point #9 above: do not omit the leading "./".

Here lies a very subtle but very important difference between the Unix/Linux "command line" and the Windows "command line." Unix/Linux does not look ordinarily in "the current directory" to resolve a command-name that you type in. It only looks through the so-called "path," and this "path" does not customarily include "the current directory."

So... if you simply type in the name of the program you've just (successfully) built... nothing happens, because Linux is not looking there. You must specify "in the current directory," which is what ./ does.

This is by design.
 
Old 02-11-2012, 10:53 AM   #6
ButterflyMelissa
Senior Member
 
Registered: Nov 2007
Location: Somewhere on my hard drive...
Distribution: Manjaro
Posts: 2,766
Blog Entries: 23

Rep: Reputation: 411Reputation: 411Reputation: 411Reputation: 411Reputation: 411
Quote:
I read your blog and iknow you do java but do you know any half descent c++ compilers because i can't find one?
All distros have the standard compiler on board. The one to look for is gcc, the gnu compiler. Everyone uses it, so, yea', this thing is pretty good

Thor
 
  


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
email programmes ambiant Linux - Software 8 01-01-2011 01:54 PM
how to run c &c++ programmes on redhat linux 7.0 veeraganesh Linux - Software 5 07-02-2008 03:35 AM
Install programmes lijoyx Linux - Newbie 1 11-05-2007 10:44 AM
how to run programmes made for windows platform in linux platform... compugeek2006 Linux - Software 1 06-26-2006 09:34 PM
how to configure apache in Suse 9.1 t run cgi programmes written in python drako123 Linux - Software 0 08-21-2004 07:27 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:35 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
Open Source Consulting | Domain Registration