| Author |
Message |
Gopher
Joined: 28 Oct 2007 Posts: 86
|
Posted: Sun 13 Jan 2008, 02:34 Post subject:
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.
Last edited by Gopher on Sun 13 Apr 2008, 02:35; edited 1 time in total
|
|
Back to top
|
|
 |
Bruce B

Joined: 18 May 2005 Posts: 10818 Location: The Peoples Republic of California
|
Posted: Sun 13 Jan 2008, 03:13 Post subject:
|
|
Would you mind posting the code?
|
|
Back to top
|
|
 |
muggins
Joined: 20 Jan 2006 Posts: 6660 Location: lisbon
|
Posted: Sun 13 Jan 2008, 03:29 Post subject:
|
|
Assuming you're using pup3.01, then you need to dload the development environment for your pupversion:
http://distro.ibiblio.org/pub/linux/distributions/puppylinux/sfs_modules-3/devx_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: |
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world\n";
return 0;
}
|
Then save as hello.cpp, then compile this with:
g++ hello.cpp -o hello , then run with hello
|
|
Back to top
|
|
 |
Lobster
Official Crustacean

Joined: 04 May 2005 Posts: 15109 Location: Paradox Realm
|
Posted: Sun 13 Jan 2008, 05:14 Post subject:
|
|
http://puppylinux.org/wikka/CategoryDevelopment
_________________ Puppy WIKI
|
|
Back to top
|
|
 |
Bruce B

Joined: 18 May 2005 Posts: 10818 Location: The Peoples Republic of California
|
Posted: Sun 13 Jan 2008, 05:53 Post subject:
|
|
| Code: | #include <iostream>
using namespace std;
int main()
{
cout << "Hello world\n";
return 0;
} |
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;
|
|
Back to top
|
|
 |
windyweather
Joined: 08 Dec 2007 Posts: 7
|
Posted: Sun 13 Jan 2008, 16:32 Post subject:
C++ stuff |
|
| 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; |
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.
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.
|
|
Back to top
|
|
 |
alienjeff

Joined: 08 Jul 2006 Posts: 2290 Location: Winsted, CT - USA
|
Posted: Sun 13 Jan 2008, 17:51 Post subject:
|
|
Start here: http://www.puppylinux.com/hard-puppy.htm and scroll down to "C/C++ Compiling"
_________________ hangout: ##arch-ftw on irc.freenode.net
diversion: http://alienjeff.net - visit The Fringe
quote: "The foundation of authority is based upon the consent of the people." - Thomas Hooker
Last edited by alienjeff on Sun 13 Jan 2008, 22:35; edited 1 time in total
|
|
Back to top
|
|
 |
Bruce B

Joined: 18 May 2005 Posts: 10818 Location: The Peoples Republic of California
|
Posted: Sun 13 Jan 2008, 22:13 Post subject:
|
|
AJ,
I think if you will make a solid reading of the OP this train wreck is not a just a compiling question. It's also a cross platform question.
My idea of C was it was intended to be portable. I'm not so sure of C++. A part of this discussion pertains to C++ and its portability.
Bruce
|
|
Back to top
|
|
 |
alienjeff

Joined: 08 Jul 2006 Posts: 2290 Location: Winsted, CT - USA
|
Posted: Sun 13 Jan 2008, 22:36 Post subject:
|
|
@BruceB: train wreck edited
_________________ hangout: ##arch-ftw on irc.freenode.net
diversion: http://alienjeff.net - visit The Fringe
quote: "The foundation of authority is based upon the consent of the people." - Thomas Hooker
|
|
Back to top
|
|
 |
Gopher
Joined: 28 Oct 2007 Posts: 86
|
Posted: Sat 12 Apr 2008, 23:42 Post subject:
|
|
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?
|
|
Back to top
|
|
 |
Pizzasgood

Joined: 04 May 2005 Posts: 6270 Location: Knoxville, TN, USA
|
Posted: Sun 13 Apr 2008, 02:03 Post subject:
|
|
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.
_________________ 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

|
|
Back to top
|
|
 |
Gopher
Joined: 28 Oct 2007 Posts: 86
|
Posted: Sun 13 Apr 2008, 02:34 Post subject:
|
|
| 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. |
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.
|
|
Back to top
|
|
 |
Khumalo
Joined: 22 Jun 2011 Posts: 1
|
Posted: Thu 23 Jun 2011, 02:49 Post subject:
Same program but jc doesn't wanna work Subject description: the "using namespace std;" is giving me an error saying "Command not found" |
|
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/distributions/puppylinux/puppy-4.3.1/devx_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
|
|
Back to top
|
|
 |
p310don
Joined: 19 May 2009 Posts: 589 Location: Brisbane, Australia
|
Posted: Thu 23 Jun 2011, 02:58 Post subject:
|
|
Khumalo,
Try typing the code directly into the console
|
|
Back to top
|
|
 |
|