#include <iostream>
using namespace std;
int main()
{
double x;
cout << "Hello Linux!/nEnter a number:";
cin >> x;
cout << "\nAh ha! " << x << " squared equals " << x*x << endl;
return 0;
}
"Hello World" troubles
I just installed Linux (RedHat 8), and, aside from the discovery that my winmodem is about as useful as a piece of cheese, I''m very happy.
Now I figured I''d try a simple "Hello World" program. I open up gedit (I have yet to figure out emacs or vi) and put together the following code:
...which I figure is a nice little test. I open up a terminal window, type g++ helloworld.cpp, and end out with a file called o.out that appears to be an executable. In fact, under file properties (in Gnome), it is marked as a binary program, and I have execute priveledges.
So, in Nautilus, I double-click it, and absolutely nothing happens. Then I open up a terminal window, go to the proper directory, type ls to make sure I''m at the right place, and then type o.out. I''m told that what I just entered isn''t a valid bash command. I then hit "Ctrl+Alt+F1" to open a virtual terminal and try again. Still no go.
So, since this should be the simplest thing in the world, where did I go wrong?
Try ./o.out
“[The clergy] believe that any portion of power confided to me, will be exerted in opposition to their schemes. And they believe rightly: for I have sworn upon the altar of God, eternal hostility against every form of tyranny over the mind of man” - Thomas Jefferson
The current directory is not normally in the command path, so you''ll have to explicitly state that you want to execute a file in the current directory: ./a.out - like the previous poster said.
If you want to name your binaries something more interesting than a.out, use the command switch -o filename, e.g. g++ testapp.cc testapp
Finally, I''m a Linux newbie myself, but I''m rather fond of a text editor that came with Linux called kate. It''s not as versatile as the more complex beasts, like vi or emacs, but it certainly beats gedit ...
If you want to name your binaries something more interesting than a.out, use the command switch -o filename, e.g. g++ testapp.cc testapp
Finally, I''m a Linux newbie myself, but I''m rather fond of a text editor that came with Linux called kate. It''s not as versatile as the more complex beasts, like vi or emacs, but it certainly beats gedit ...
I though u needed a better explanation so, the problem is you think that the current directory is in the path, IT ISNT. try:
./a.out
as Tron says or more dangerously you could add the current directory to the path:
export PATH=$PATH:.
but i wouldnt reccomend this, if you want to know why not just think about creating a script
#!/bin/sh
rm -rf /
and calling it ls
imagine if root executed ls in this directory,.... uh-oh
./a.out
as Tron says or more dangerously you could add the current directory to the path:
export PATH=$PATH:.
but i wouldnt reccomend this, if you want to know why not just think about creating a script
#!/bin/sh
rm -rf /
and calling it ls
imagine if root executed ls in this directory,.... uh-oh
April 21, 2003 10:03 PM
Try gcc -c example.cxx -o example
./example
Drop Gedit there are many emacs and vi tutorials.
./example
Drop Gedit there are many emacs and vi tutorials.
quote:
Original post by TerranFury
I just installed Linux (RedHat 8), and, aside from the discovery that my winmodem is about as useful as a piece of cheese, I'm very happy.
Now I figured I'd try a simple "Hello World" program. I open up gedit (I have yet to figure out emacs or vi) and put together the following code:
...which I figure is a nice little test. I open up a terminal window, type g++ helloworld.cpp, and end out with a file called o.out that appears to be an executable. In fact, under file properties (in Gnome), it is marked as a binary program, and I have execute priveledges.
So, in Nautilus, I double-click it, and absolutely nothing happens. Then I open up a terminal window, go to the proper directory, type ls to make sure I'm at the right place, and then type o.out. I'm told that what I just entered isn't a valid bash command. I then hit "Ctrl+Alt+F1" to open a virtual terminal and try again. Still no go.
So, since this should be the simplest thing in the world, where did I go wrong?
First things first, when you compile using g++ helloworld.cpp, add "-o helloworld" to the line (withouth the quotes), that will name the executable as helloworld. Second, as a safety precaution, the "." or current working directory is not part of the path anymore and hasn't been for quite some time. So just type ./
export PATH=.:$PATH
and that way, you'll be able to simply type the name of the file to run it. But, keep in mind that adding the "." to the path is considered a security hasard by some.
[Cyberdrek | the last true sorcerer | Spirit Mage - mutedfaith.com][ Administrator TheLinuxForum.tk]
[edited by - cyberdrek on April 23, 2003 10:39:11 AM]
[Cyberdrek | ]
I would HIGHLY recommend NOT adding the current directory to the path for all the reasons outlined above.
I''ve been using Linux for just over a year now and you do get used to these little "quirks" quite quickly.
I asked the same question myself about the need for ./progname and they gave me the same answer about a malicious script.
Parallel Realities
Project: Starfighter
I''ve been using Linux for just over a year now and you do get used to these little "quirks" quite quickly.
I asked the same question myself about the need for ./progname and they gave me the same answer about a malicious script.
Parallel Realities
Project: Starfighter
Parallel RealitiesProject: Starfighter
I use g++ -o exe.exe filename.cpp... Is that bad?
-~-The Cow of Darkness-~-
-~-The Cow of Darkness-~-
-~-The Cow of Darkness-~-
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement