Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Wed 30 Jul 2014, 21:20
All times are UTC - 4
 Forum index » House Training » Beginners Help ( Start Here)
How to compile and run c++ code? (solved)
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [14 Posts]  
Author Message
Gopher

Joined: 28 Oct 2007
Posts: 86

PostPosted: 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
View user's profile Send private message 
Bruce B


Joined: 18 May 2005
Posts: 11080
Location: The Peoples Republic of California

PostPosted: Sun 13 Jan 2008, 03:13    Post subject:  

Would you mind posting the code?
Back to top
View user's profile Send private message 
muggins

Joined: 20 Jan 2006
Posts: 6673
Location: lisbon

PostPosted: 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
View user's profile Send private message 
Lobster
Official Crustacean


Joined: 04 May 2005
Posts: 15117
Location: Paradox Realm

PostPosted: Sun 13 Jan 2008, 05:14    Post subject:  

http://puppylinux.org/wikka/CategoryDevelopment
_________________
Puppy WIKI
Back to top
View user's profile Send private message Visit poster's website 
Bruce B


Joined: 18 May 2005
Posts: 11080
Location: The Peoples Republic of California

PostPosted: 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
View user's profile Send private message 
windyweather

Joined: 08 Dec 2007
Posts: 7

PostPosted: 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
View user's profile Send private message 
alienjeff


Joined: 08 Jul 2006
Posts: 2291
Location: Winsted, CT - USA

PostPosted: 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: ##b0rked 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
View user's profile Send private message 
Bruce B


Joined: 18 May 2005
Posts: 11080
Location: The Peoples Republic of California

PostPosted: 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
View user's profile Send private message 
alienjeff


Joined: 08 Jul 2006
Posts: 2291
Location: Winsted, CT - USA

PostPosted: Sun 13 Jan 2008, 22:36    Post subject:  

@BruceB: train wreck edited
_________________
hangout: ##b0rked 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
View user's profile Send private message 
Gopher

Joined: 28 Oct 2007
Posts: 86

PostPosted: 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
View user's profile Send private message 
Pizzasgood


Joined: 04 May 2005
Posts: 6270
Location: Knoxville, TN, USA

PostPosted: 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
View user's profile Send private message Visit poster's website 
Gopher

Joined: 28 Oct 2007
Posts: 86

PostPosted: 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
View user's profile Send private message 
Khumalo

Joined: 22 Jun 2011
Posts: 1

PostPosted: 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
View user's profile Send private message 
p310don

Joined: 19 May 2009
Posts: 689
Location: Brisbane, Australia

PostPosted: Thu 23 Jun 2011, 02:58    Post subject:  

Khumalo,

Try typing the code directly into the console
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [14 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » Beginners Help ( Start Here)
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0806s ][ Queries: 11 (0.0094s) ][ GZIP on ]