Malcolm Hunter wrote:
--- Ursprüngliche Nachricht ---
Von: StuartBird <[EMAIL PROTECTED]>
An: Peterborough LUG - No commercial posts <[email protected]>
Betreff: [Peterboro] A Bit of Path Trouble !
Datum: Tue, 07 Mar 2006 14:11:59 +0000
Hi All
I have very recently been trying to teach myself the black art of
programming in C++, without a great deal of success. (Although it is
still very early days).
I have found a tutorial to follow but seem to be stumbling a bit at the
first hurdle. Here is the problem:
The tutorial provides this script for compiling the code from the
command line:
#/bin/sh
Did you mean #!/bin/sh ?
echo compiling C++ using -ansi -pedantic-errors -Wall
g++ -ansi -pedantic-errors -Wall $1 $2 $3
You could create the file in ~/bin and add ~/bin to the PATH statement in
the system login script (e.g. /etc/profile - if it's not there already) or
your own .bash_profile or .bashrc.
which I would like to be able to run from anywhere simply by entering
"gccp" (the script name).
I have tried creating the script at /home/stu, chmod a+x on it, then try
to run it but it won't run without a ./ in front of it.
This is because . isn't in your PATH, which it should never be!
I the tried creating the script as root in /usr/bin, again chmod a+x
then changed its owner and user to stu:users so I could run it from my
own account. Now it only runs when I enter /usr/bin/gccp. I can live
with that but when I tried it on a file I had another unexpected problem.
I created a file called temp.cpp in /home/stu/dev-files/test whilst in
that directory. I then ran my /usr/bin/gccp script but it would not
work.
What do you mean by "would not work"? Have you checked the permissions on
that directory?
I then cd'd out to /home/stu and ran:
/usr/bin/gccp /home/stu/dev-files/test/temp.cpp
and it compiled the code with no errors (yippeeee I thought). But....
...the tutorial states that once you have run the script across
temp.cpp, another file called a.out should be created in the same
directory. You then run ./a.out and good old hello world appears at the
prompt. My a.out however ended up in /home/stu rather than in
/dev-files/test.
The a.out files works okay and I get Hello World ! followed by a new line.
I believe that this is a path issue but cannot seem to get it set up
correctly. At this rate my system will be littered with compiled test
files and I don't seem to have any control over where they go.
I can post a copy of echo $PATH if that would help.
Any help appreciated.
HTH
Malc
Thanks Malcolm
Did you mean #!/bin/sh ?
Yes I did, typo on my part. (in the e-mail, not the script).
You could create the file in ~/bin and add ~/bin to the PATH statement in
the system login script (e.g. /etc/profile - if it's not there already)
I created the script in ~/bin and everything nows works as it should, ie
I just have to enter "gccp" from wherever I am working and it compiles
the code, then creates the a.out file in the folder that I am currently in.
I don't know why it did not work like that in /usr/bin, as that is also
in my path ?
Anyhow, all working now.
Thanks mate.
Stu
_______________________________________________
Peterboro mailing list
[email protected]
http://mailman.lug.org.uk/mailman/listinfo/peterboro