How to compile and run c++ code? (solved)
How to compile and run c++ code? (solved)
I guess as long as I'm posting here, I may as well ask the other question I was planning to ask. I know even less about the terminology concerning this topic than most, so bear with me.
Before I switched to Puppy, I enjoyed playing around with simple "hello world" type programs with Bloodshed's Dev++. I'm wondering how I might go about doing something similar on Puppy. How could I go about compiling and running simple programs on Puppy? Are there any significant differences as far the structure of the code itself between the two OSs? I'd look for the answer myself, but I'm not sure where to start. Any help is appreciated.
Before I switched to Puppy, I enjoyed playing around with simple "hello world" type programs with Bloodshed's Dev++. I'm wondering how I might go about doing something similar on Puppy. How could I go about compiling and running simple programs on Puppy? Are there any significant differences as far the structure of the code itself between the two OSs? I'd look for the answer myself, but I'm not sure where to start. Any help is appreciated.
Last edited by Gopher on Sun 13 Apr 2008, 06:35, edited 1 time in total.
Assuming you're using pup3.01, then you need to dload the development environment for your pupversion:
http://distro.ibiblio.org/pub/linux/dis ... vx_301.sfs
save this to same location as you're pup_save.2fs file, then reboot. If you open a console, and entering gcc -v returns the version number, then you've got a working compiler.
Open a text editor, like geany, and enter:
Then save as hello.cpp, then compile this with:
g++ hello.cpp -o hello , then run with hello
http://distro.ibiblio.org/pub/linux/dis ... vx_301.sfs
save this to same location as you're pup_save.2fs file, then reboot. If you open a console, and entering gcc -v returns the version number, then you've got a working compiler.
Open a text editor, like geany, and enter:
Code: Select all
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world\n";
return 0;
}
g++ hello.cpp -o hello , then run with hello
Code: Select all
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world\n";
return 0;
}
What's this for:
cout <<
and this apparently is something C++ recognizes but it looks like a sentence, is C++ less cryptic than C?
using namespace std;
-
- Posts: 7
- Joined: Sun 09 Dec 2007, 01:50
C++ stuff
namespace sets up to use the std library which is a standard library of classes and io. It avoids using std:: in front of all the classes from that library.Bruce B wrote:
I've never paid much attention to C++ but do like C
What's this for:
cout <<
and this apparently is something C++ recognizes but it looks like a sentence, is C++ less cryptic than C?
using namespace std;
cout << - cout is "standard output" and "<<" is "overridden" as an operator to perform output. So this statement is a lot like "printf" with automatic format conversion based on the type of the variables.
Start here: http://www.puppylinux.com/hard-puppy.htm and scroll down to "C/C++ Compiling"
Last edited by alienjeff on Mon 14 Jan 2008, 02:35, edited 1 time in total.
[size=84][i]hangout:[/i] ##b0rked on irc.freenode.net
[i]diversion:[/i] [url]http://alienjeff.net[/url] - visit The Fringe
[i]quote:[/i] "The foundation of authority is based upon the consent of the people." - Thomas Hooker[/size]
[i]diversion:[/i] [url]http://alienjeff.net[/url] - visit The Fringe
[i]quote:[/i] "The foundation of authority is based upon the consent of the people." - Thomas Hooker[/size]
Ok, thank you everyone for your help, and sorry for not saying it earlier. I recently decided to try this again, and after awhile I managed to get the development environment downloaded and installed. However, I tried to use muggins's example to test it out, and ran into some problems.
At first, it was giving me an error that there was no "newline" at end of file. I added an extra line to the code and it stopped complaining about that, to my surprise. Since it didn't give me any feedback when I ran the compile command again, I assumed it was successful. How do I run it now? I assumed I just typed "hello" into the console, but it doesn't recognize that command. How do I run a program compiled in this way?
At first, it was giving me an error that there was no "newline" at end of file. I added an extra line to the code and it stopped complaining about that, to my surprise. Since it didn't give me any feedback when I ran the compile command again, I assumed it was successful. How do I run it now? I assumed I just typed "hello" into the console, but it doesn't recognize that command. How do I run a program compiled in this way?
- Pizzasgood
- Posts: 6183
- Joined: Wed 04 May 2005, 20:28
- Location: Knoxville, TN, USA
Since it's not already in the $PATH, you'll have to run it explicitly. From the same directory, run the command ./hello to do that. The ./ means "current directory". Alternately, you could type out the full path.
To see the $PATH variable, run echo $PATH. Things in those directories can be run without adding a path to them.
To see the $PATH variable, run echo $PATH. Things in those directories can be run without adding a path to them.
[size=75]Between depriving a man of one hour from his life and depriving him of his life there exists only a difference of degree. --Muad'Dib[/size]
[img]http://www.browserloadofcoolness.com/sig.png[/img]
[img]http://www.browserloadofcoolness.com/sig.png[/img]
Excellent, now it works fine. Thank you very much, and with that, I think this topic can be considered solved. Thanks again for your help everyone.Pizzasgood wrote:Since it's not already in the $PATH, you'll have to run it explicitly. From the same directory, run the command ./hello to do that. The ./ means "current directory". Alternately, you could type out the full path.
Same program but jc doesn't wanna work
am using puppy linux for my progams, tryed compiling my programs but it just dousn't wanna work
even tryed the "Hello World" simple one
The error is
Line 3 : using : command not found
on the line "using namespace std;"
and yes i dloaded the compiler from http://distro.ibiblio.org/pub/linux/dis ... vx_431.sfs
since am using pup_431.sfs
i've never used linux b4 so am clueless
I used edit to type the code and console to run it
even tryed the "Hello World" simple one
The error is
Line 3 : using : command not found
on the line "using namespace std;"
and yes i dloaded the compiler from http://distro.ibiblio.org/pub/linux/dis ... vx_431.sfs
since am using pup_431.sfs
i've never used linux b4 so am clueless
I used edit to type the code and console to run it