Page 1 of 1

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

Posted: Sun 13 Jan 2008, 06:34
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.

Posted: Sun 13 Jan 2008, 07:13
by Bruce B
Would you mind posting the code?

Posted: Sun 13 Jan 2008, 07:29
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

Posted: Sun 13 Jan 2008, 09:14
by Lobster

Posted: Sun 13 Jan 2008, 09:53
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;

C++ stuff

Posted: Sun 13 Jan 2008, 20:32
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.

Posted: Sun 13 Jan 2008, 21:51
by alienjeff
Start here: http://www.puppylinux.com/hard-puppy.htm and scroll down to "C/C++ Compiling"

Posted: Mon 14 Jan 2008, 02:13
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

Posted: Mon 14 Jan 2008, 02:36
by alienjeff
@BruceB: train wreck edited

Posted: Sun 13 Apr 2008, 03:42
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?

Posted: Sun 13 Apr 2008, 06:03
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.

Posted: Sun 13 Apr 2008, 06:34
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.

Same program but jc doesn't wanna work

Posted: Thu 23 Jun 2011, 06:49
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

Posted: Thu 23 Jun 2011, 06:58
by p310don
Khumalo,

Try typing the code directly into the console