|
Acorn Arcade forums: Programming: Setting a file path in !Run for a library file in g++?
|
Setting a file path in !Run for a library file in g++? |
|
Cauchy (21:58 11/2/2013) swirlythingy (23:27 11/2/2013) Cauchy (00:18 12/2/2013) sirbod (08:47 12/2/2013) swirlythingy (11:30 12/2/2013) Cauchy (15:49 12/2/2013) sirbod (08:43 12/2/2013)
|
|
John O'Meara |
Message #121895, posted by Cauchy at 21:58, 11/2/2013 |
Member
Posts: 43
|
Hi, I am trying to setup a path for a small library called !MyLibrary to use with g++ programs. The !MyLibrary is in $.Programs.!MyLibrary; the contents of its !Boot file are: If "<MyLibrary$Dir>" = "" Then Set MyLibrary$Dir <Obey$Dir> And the contents of its !Run file are: Set MyLibrary$Dir <Obey$Dir> If "<MyLibrary$Path>" = "" Then Set MyLibrary$Path MyLibrary:lib. The !MyLibrary application directory contains a directory called lib, which in turn contains the file libwindow/a. So I am trying to access this file in: $.Programs.!MyLibrary.lib.libwindow/a, for g++ as follows: *g++ -LMyLibrary: -lwindow wintest1.cpp Where wintest1 is in: $.Programs.devWin.cpp When I use g++ as above I get a: ...:cannot find -lwindow collect2: ld returned 1 exit status. However, if I move libwindow/a file out of the directory lib, and put it along side the lib folder; g++ compiles it and generates the file a/out, ok. But I want to use the libwindow/a library file from inside the lib folder. I know next to nothing about search paths in Obey files like !Run as above. I am hoping someone will be able to help. Thanking you in advance. |
|
[ Log in to reply ] |
|
Martin Bazley |
Message #121896, posted by swirlythingy at 23:27, 11/2/2013, in reply to message #121895 |
Posts: 460
|
I don't know much about how GCC interprets its environment and/or command line arguments, and I suspect that, like most things about C on RISC OS, it's more than slightly icky, but I'm a bit worried about this line:
If "<MyLibrary$Path>" = "" Then Set MyLibrary$Path MyLibrary:lib.
You do realise that's a circular reference, right? You check to see if the path "MyLibrary:" exists, and if it doesn't, then you initialise it to "MyLibrary:". If you're really executing that, I'm not surprised it doesn't work!
Are you a new RISC OS user? It sounds as if you're not at all sure about how application directories work. |
|
[ Log in to reply ] |
|
John O'Meara |
Message #121897, posted by Cauchy at 00:18, 12/2/2013, in reply to message #121896 |
Member
Posts: 43
|
I am not that new to the RISC OS, I have an iyonix since 2008, and I learned BBC BASIC in the past a long time before that in an ad hoc way, but now that I have time I want to know more about RISCOS; I do not know what language: If "<MyLibrary$Path>" = "" Then Set MyLibrary$Path MyLibrary:lib., is. I just copied that from something similar out of other application !Run files; you would be ages searching for the specifics of this in the PRM, unless you knew where to look. I was under the impression that the line you quote meant If MyLibrary$Path is unset then set it to <MyLibrary$Dir>.lib. I did not know it meant "doesn't exist".What is the purpose of the <> brackets, and why are they used sometimes and not other times in expressions. Is there any booklet on the "language", and where can I get it if there is? |
|
[ Log in to reply ] |
|
Jon Abbott |
Message #121898, posted by sirbod at 08:43, 12/2/2013, in reply to message #121895 |
Member
Posts: 563
|
Unless there's a reason for it being there, avoid the !Boot and shift the path variable to the !Run:
If "<MyLibrary$Path>" = "" Then Set MyLibrary$Path <Obey$Dir>
And unless its going to be changed externally, don't bother with the check:
Set MyLibrary$Path <Obey$Dir> |
|
[ Log in to reply ] |
|
Jon Abbott |
Message #121899, posted by sirbod at 08:47, 12/2/2013, in reply to message #121897 |
Member
Posts: 563
|
These are just OS commands, there's a list of them on this site: http://www.iconbar.com/forums/viewthread.php?threadid=10981#comments
The angled brackets tell the OS to use the contents of the variable within them. |
|
[ Log in to reply ] |
|
Martin Bazley |
Message #121901, posted by swirlythingy at 11:30, 12/2/2013, in reply to message #121897 |
Posts: 460
|
I am not that new to the RISC OS Just RISC OS. Not "The RISC OS".
You wouldn't have copied that line out of any other application !Run file, because, as I just told you, it's utter nonsense. I don't think this is a thread about G++ so much as it is a thread about the elementary use of star commands.
And I asked if you were new to RISC OS because, from the contents of your post, you didn't seem to have much of an idea what a !Boot or a !Run file did, or what the difference between them was.
I'm sure there are proper guides and tutorials out there for those who are willing to look, but here's a brief list of all the problems you've had thus far:
Applications are directories which begin with the character "!".
The !Boot file in an application directory is run whenever the directory containing the application is opened.
The !Run file is run when you double-click on the application.
System variables are conventionally, although not compulsorily, named in the format AppName$VarName.
Any part of a filename which appears inside angle brackets will be substituted with the value of that variable. This allows you to refer to <MyApp$Dir>.!Run, instead of ADFS::HardDisc4.$.Programs.MyApp.!MyApp.!Run.
The Set command can be used to write the value of a variable. It has the format Set AppName$VarName value , where value is subject to the same angle-bracket-substitution rules as filenames. Thus you can set a variable to the value of another variable using Set AppName$VarName <OtherAppName$OtherVarName> .
Whenever an Obey file is run, a variable called Obey$Dir is set to the directory in which that Obey file is located.
The main means of reading the value of a variable is by referring to it in a filename or another variable assignment, as above, but you can also use the If command, as in If "<AppName$VarName>" = "value" Then (...) Else (...) . The double quotes are necessary to ensure that you are comparing two strings. Note, once again, the use of angle brackets to denote that you wish the variable name to be substituted with its value.
If a variable does not exist at the time its value is looked up for whatever reason, it will evaluate to the empty string. Thus you can compare a variable against an empty string to determine whether or not it exists, e.g. If "<AppName$VarName>" = "" Then (...) .
All variables whose name ends in "$Path" are subject to special treatment by the OS when evaluating filenames. For a variable called MyApp$Path, you can refer to a filename by "MyApp:Resources.Templates" or whatever. The leading "MyApp:" will be replaced by the value of the variable. Note that this means the variable must end in a trailing full stop, otherwise the naive substitution would end up producing a filename like "Programs.MyApp.!MyAppResources". Jon forgot about this in his post!
Finally, path variables may have multiple entries, in which case the OS will try to evaluate each in turn until it finds a file which exists. So you could first issue Set MyLib$Path <MyApp$Dir>.lib.,<MyApp$Dir>.other_lib.,<GCC$Dir>.yet_another_lib. and then Run MyLib:MyMakefile to search for the file "MyMakefile" in those three distinct places (precedence left to right) and only produce a 'File not found' error if it couldn't be found in any of them. |
|
[ Log in to reply ] |
|
John O'Meara |
Message #121904, posted by Cauchy at 15:49, 12/2/2013, in reply to message #121901 |
Member
Posts: 43
|
Thank you both for your replies and your time. The explaination you have given Martin is really what I was looking for, it helps alot. I only knew some of those things you listed like, path variables can have multiple entries. A line I had at the time in mind is in !Draw.!Run, and is: If "<Draw$PrintFile>" = "" Then Set Draw$PrintFile printer: Thanks again. |
|
[ Log in to reply ] |
|
|
Acorn Arcade forums: Programming: Setting a file path in !Run for a library file in g++? | |
|