How to compile and run c++ code? (solved)

Booting, installing, newbie
Post Reply
Message
Author
Gopher
Posts: 86
Joined: Sun 28 Oct 2007, 04:33

How to compile and run c++ code? (solved)

#1 Post by Gopher »

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, 06:35, edited 1 time in total.

Bruce B

#2 Post by Bruce B »

Would you mind posting the code?

muggins
Posts: 6724
Joined: Fri 20 Jan 2006, 10:44
Location: hobart

#3 Post by muggins »

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:

Code: Select all

#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

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#4 Post by Lobster »

Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

Bruce B

#5 Post by Bruce B »

Code: Select all

#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;

windyweather
Posts: 7
Joined: Sun 09 Dec 2007, 01:50

C++ stuff

#6 Post by windyweather »

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.

User avatar
alienjeff
Posts: 2265
Joined: Sat 08 Jul 2006, 20:19
Location: Winsted, CT - USA

#7 Post by alienjeff »

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]

Bruce B

#8 Post by Bruce B »

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

User avatar
alienjeff
Posts: 2265
Joined: Sat 08 Jul 2006, 20:19
Location: Winsted, CT - USA

#9 Post by alienjeff »

@BruceB: train wreck edited
[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]

Gopher
Posts: 86
Joined: Sun 28 Oct 2007, 04:33

#10 Post by Gopher »

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?

User avatar
Pizzasgood
Posts: 6183
Joined: Wed 04 May 2005, 20:28
Location: Knoxville, TN, USA

#11 Post by Pizzasgood »

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.
[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]

Gopher
Posts: 86
Joined: Sun 28 Oct 2007, 04:33

#12 Post by Gopher »

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.

Khumalo
Posts: 1
Joined: Wed 22 Jun 2011, 14:14

Same program but jc doesn't wanna work

#13 Post by Khumalo »

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

p310don
Posts: 1492
Joined: Tue 19 May 2009, 23:11
Location: Brisbane, Australia

#14 Post by p310don »

Khumalo,

Try typing the code directly into the console

Post Reply