First very basic linux programming attempt didn't quite work

Need help with C, C++, perl, python, etc?

First very basic linux programming attempt didn't quite work

Postby Ed Hall » 2007-02-12 03:36

I looked around for some beginning programming info for moving from the "other" world to linux and it looked like it should be easy, but the following failed. Am I on a wrong track or just at a bump?

I made a directory called "Programming" and created a file called FirstTry.c which held the following text:

Code: Select all
#include "iostream"
  int main()
    std::cout << "Hello! First try...\n";
    return 0;

I then used "g++ -c FirstTry.c" which created "FirstTry.o"

All seemed well.

Next, I used "g++ FirstTry.o -o FirstTry" which created "FirstTry"

Again, all seemed well.

All, except that, FirstTry doesn't run. I get the following:

"bash: FirstTry: command not found"

I tried also to run it from File Browser and it does nothing, even if I try to open it in a new window.

This doesn't seem to be the same type problem as I've had in the past where the program closes the window too fast to see it happen, since the bash error came up in the terminal. What might I be missing?

Additionally, is there a tutorial for writing applications for Gnome like the "forger's tutorial" teaches win32 programming? Or is Gnome programming entirely different?

Thanks for all help. This really isn't a front burner issue for me just yet, but since I can program for DOS and Win32, I thought I'd like to learn some about linux. I am currently moving my computers to linux based OSs.

Take Care,
Ed Hall
Ed Hall

Postby chealer » 2007-02-12 03:48

Enter the full absolute path to the file.
Posts: 671
Joined: 2005-09-24 16:11
Location: Kebekia, Kanada

Postby Grifter » 2007-02-12 03:50

to run a binary in the dir you're in, ./filename
alternatively, the whole path, /home/luser/programming/filename

in order to just type filename, it would have to be in one of the bin dirs which is in your $PATH variable
Eagles may soar, but weasels don't get sucked into jet engines...
Posts: 1572
Joined: 2006-05-04 07:53
Location: Svea Rike

Postby Optional » 2007-02-12 03:54

You can combine those commands, i.e.: g++ FirstTry.c -o FirstTry

Or is Gnome programming entirely different?

You would want to Google GTK+ programming, and there are many guides.
User avatar
Posts: 349
Joined: 2007-02-05 05:02

Postby Ed Hall » 2007-02-12 04:52


"./FirstTry" worked like a champ! I understand the path variable, but not where it resides. I'll figure that part out later and add my Programming directory to it for future work.

I took a look at the GTK+ and it doesn't seem too confusing; at least not yet. I'll give it a longer look as soon as I can.

Thanks again for all the help. I have a couple of extensive win32 programs I'd like to make linux equivalents of. I'll have to see where they lead.

Oh, and thanks for the combined form. I tried that first, but split them up to check the steps when it wouldn't run.

Take Care,
Ed Hall
Ed Hall

Postby Optional » 2007-02-12 05:19

To see all the environment variables available, type "export" by itself at your terminal of choice.

To add a directory to the $PATH variable, use (at the terminal again):


Then you can run anything inside /your/new/path/here simply by calling the program/script name (remember, they need to be executable!)
User avatar
Posts: 349
Joined: 2007-02-05 05:02

Postby Ed Hall » 2007-02-12 18:40

Thanks, again, Optional,

That worked well, but my attempts to make it permanent (such as adding it to my userid/.bash_profile) didn't. It is not a pressing issue for now anyway. Thanks again for all the help.

Take Care,
Ed Hall

Update to previous post

Postby Ed Hall » 2007-02-12 18:55

I added the new PATH in user/.bashrc and all is fine...

Take Care,
Ed Hall

Return to Programming

Who is online

Users browsing this forum: No registered users and 5 guests