Page 1 of 4

gcc and RISC OS

Posted: Tue Nov 13, 2012 11:22 am
by nr.
(posting here rather than the programming forum, as I think this is RISC OS implementation specific, rather than a generic C/C++ question)

Has anyone managed to get gcc working on RISC OS yet? I'm trying, but not having much luck... I downloaded GCC4 and GCC4-C++ from http://www.riscos.info/packages/Develop ... .html#gcc4, unzipped them into Apps.Development, and installed the Sharedlibs from !PackMan. I can run gcc -v to report a version number, but not actually get anything to compile:

Code: Select all

*gcc -v
Using built-in specs.
Target: arm-unknown-riscos
Configured with: /home/joty/projects/gccsdk/gccsdk_svn1/gcc4/srcdir/gcc/configure --host=arm-unknown-riscos --target=arm-unknown-riscos --prefix=/home/joty/projects/gccsdk/gccsdk_svn1/gcc4/release-area/full/!GCC --enable-threads=posix --enable-sjlj-exceptions=no --enable-c99 --enable-cmath --enable-multilib --enable-shared=libunixlib,libgcc,libstdc++ --disable-c-mbchar --disable-wchar_t --disable-libstdcxx-pch --disable-tls --with-cross-host --with-pkgversion=GCCSDK GCC 4.1.2 Release 1 Development --with-bugurl=http://gccsdk.riscos.info/ --enable-maintainer-mode --enable-interwork --disable-nls --enable-checking=no --enable-languages=c,c++
Thread model: posix
gcc version 4.1.2 (GCCSDK GCC 4.1.2 Release 2)

*gcc helloworld
helloworld: file not recognized: File format not recognized
collect2: ld returned 1 exit status

*list helloworld
   1 /* c.hellow.
   2 
   3    The simple Hello World application.  */
   4 
   5 #include <stdio.h>
   6 
   7 int main (void)
   8 {
   9   printf ("Hello World\n");
  10   return 0;
  11 }
*
I have no idea what all the /home/joty/ stuff is in the gcc configuration options. Any ideas anyone? Should I have downloaded from /downloads/gccsdk/latest instead?

Ta,

Re: gcc and RISC OS

Posted: Tue Nov 13, 2012 12:54 pm
by nr.
Ah!

Think I'm getting somewhere. It's all to do with filenaming, and RISC OS using a '.' as a directory seperator. If I create a sub-directory, 'c', then move the source code to that directory, I can then compile it with 'gcc c.helloworld' rather than 'gcc helloworld.c'

Blimey. That wasn't too intuitive really.

Ta,

Re: gcc and RISC OS

Posted: Tue Nov 13, 2012 1:03 pm
by pygmy_giant
Sounds like you've stepped through the looking glass!

Thanks for posting this - I was about to ask the same question!

I came a cropper with a manual install, so I will try copying what you've done.

Great to see someone with it actually working!

GCC on RISCOS opens the door to porting and streamlined code execution.

Re: gcc and RISC OS

Posted: Tue Nov 13, 2012 1:18 pm
by nr.
It's probably worth mentioning that I ended up downloading gccsdk-gcc-core-bin.zip from http://www.riscos.info/downloads/gccsdk/latest/ rather than using the earlier link. This version also gives you a !System file that you can merge (use the System function in !Configure), making the installation not quite totally manual. Well, at least I suspect that's what you're meant to do with it. Nothing appears to have broken anyway.

I haven't got around to trying to get make to work yet. I rather think I need a large cup of tea before I start to think about that.

Still. Onwards and upwards. I've got 'hello world' compiling and running now, which is always a nice thing on a new platform.

Ta,

Re: gcc and RISC OS

Posted: Tue Nov 13, 2012 3:29 pm
by pygmy_giant
I thought the SDK was a cross-compiler...?

Re: gcc and RISC OS

Posted: Tue Nov 13, 2012 4:07 pm
by poglad
I'm sure you shouldn't have to place your source code in a directory named 'c'. Instead of compiling hello.c, I think you compile hello/c instead? You just swap / and . as they are used for equal and opposite functions in RISCOS compared with Linux. [Says me as a total newbie, but the . for directories thing dates back to the BBC Micro hehe!]

Re: gcc and RISC OS

Posted: Tue Nov 13, 2012 4:19 pm
by nr.
I tried using / rather than . in the filename, but the compilation still failed with the same error. Of course, it could be just that I was doing that wrong as well :)

Ta,

Re: gcc and RISC OS

Posted: Fri Nov 16, 2012 10:06 am
by Shawty
Hi All,

Ass a veteran of Risc-OS and more specifically a veteran who also used to write software for the OS, in C using the original Acorn C / Norcroft product I can assure you that the directory naming is very much the correct thing to do. :-)

Let me explain why...

Risc-OS uses a system of file types to identify the contents of a file to open and what application to open it with. Windows (and other extension based apps and systems) do not use this file type system (As you most likely know) instead they use the '.ext' way of doing things.

now in general this doesn't present too much of an issue for risc os, and some of the erlier programs such as !PC handled the translation by changing the seperator, EG:

myfile.txt

became

myfile\txt

Thus giving the file a single file in a single location.

However, this meant that applications for Risc-OS had to be specially written to take note of and perform this translation, and that then meant that they didn't work correctly when used back on non Risc-OS systems.

This meant that when porting apps across which relied hevily on using extensions (Such as C compilers) it wasn't really feasable to change every code point in the project to do the translation from . to \ and still keep a sane build that would work across all platforms.

Thus a decision was made, to leave . as the extension separator in most apps, knowing that the Risc-OS path separator is a . also

This meant that apps relying on extensions could continue to work as long as the path separator was honoured and in order to make sure this hounouring took place, changes where made to the underlying operating system in "OS_FIle" , and the "OS_FIler" related modules such as "Fileswitch" & "ADFS_Filer" (If your wondering what all of these are... press F12 type *mod. and press return) to make sure that when a call for an extensioned file was made, that the result was translated to <directory>.<filename>

Thus in todays modern world, as you've already figured out you now get:

myprog.c = c.myprog (A text file called my prog in a folder called c)
myprog.o = o,myprog

and so on.

acorns original development guide lines for creating project folders where always as follows (This is all detailed in the Rosc-OS 3 programmers reference manuals)

<projname>
<c>
<o>
<s>
<cc>
<doc>
<tmp>

c was for c sources
o for object files
s was for assembler files
cc was for c++ files (although I always used to just use c)
doc was for documents
tmp was where temporary files where created

On top of that, if you want to create a runnable application from your compiled code, then there's a whole other directory layout "The application standard directory" that you also need to obey.

Cheers

Peter "Shawty" Shaw

Re: gcc and RISC OS

Posted: Fri Nov 16, 2012 12:27 pm
by Shawty
Please note in my previous post the

<c>, <o>, <s> etc directories are nested under the <Projname> directory (I havent figured out how to do code & indentation on the forum yet :-)

Shawty

Re: gcc and RISC OS

Posted: Mon Nov 19, 2012 12:12 am
by theom
Just to clear up a few things:

The /home/joty stuff is the paths on the build machine (John Tytgat's) - the GCC binaries are cross-compiled hence these are Linux paths.

You don't have to use the RISC OS C code naming convention. You can call your files source/c and header/h and GCC should find them. The original reason for Projname.c.source and Projname.h.header was that originally ADFS discs were limited to 77 (or worse 47) files per directory and this was a bit awkward for many C projects.

There are some notes on filename translation here:
http://www.riscos.info/index.php/RISC_O ... ranslation
http://www.riscos.info/index.php/UnixLib
and here (which is very old, but I can't find a newer document that describes it) - specifically that you can use UnixEnv$progname$sfix to change which suffixes are swapped and which aren't:
http://www.riscos.infowebsvn/filedetail ... 18&peg=918

The above mostly applies just to programs built with UnixLib (like GCC), which is aimed at easing the translation between programs expecting Unix filenames and those expecting RISC OS names. They don't always get it right, but it makes it a lot easier to port programs from Unix.

Re: gcc and RISC OS

Posted: Mon Dec 10, 2012 7:51 pm
by pygmy_giant
I have been successfully compiling from within a folder called 'c' but still don't understand why I have to.

I am confused so I will re-read the above thread slowly (with a cup of tea).

My code is getting long and waffly and I want to chop it up into managable chunks and so am trying to learn how to create simple makefiles.

Is this namining convention pecularity a potential banana skin when using make?

Where is the best 'makefiles for dummies' resource on the net?

ta.

Re: gcc and RISC OS

Posted: Wed Dec 12, 2012 8:28 pm
by Shawty
@pmgmy_giant - cant help you with make files (I always use Obey files) but putting your files into a folder called c in smaller chunks should not present a problem.

As far as make and other utils will see it, they should just be able to read 'file.c' and the OS will translate as needed.

However, as @theom says, you don't have to do it that way, you can just call it 'file\c' and it should still work as long as you use the correct name conventions in your make files

Re: gcc and RISC OS

Posted: Sat Dec 15, 2012 8:36 pm
by pygmy_giant
Thanks for the reply - tearing my hair out a bit as I was able to compile from the command line but seem to be getting linker errors of late. Weirdly I can compile from the StrongArm text editor using the little running man / F10....

Might avoid Make all together and use the GCC command for compiling ultiple files as outlined on this page: http://pages.cs.wisc.edu/~beechung/ref/gcc-intro.html

Guess I could just put that in an Obey file?

Re: gcc and RISC OS

Posted: Sat Dec 15, 2012 9:27 pm
by Shawty
If your actually running the full PI based Risc OS desktop, then the one recommendation I have for you is to use StrongED

StrongED has been around since the days of the original RiscOS 3.11 and it worked fantastic then, just as it does today.

It respects which ever way you do your file naming, and you can set it up to run your compilers directly from within the editor using the run command.

No space here to go into specifics, but delve in the the stonghelp manual that comes with stronged (Strong Help is a stronged companion you should absolutely have installed) and it should explain everything.

Re: gcc and RISC OS

Posted: Sat Dec 15, 2012 10:15 pm
by pygmy_giant
I perspnally prefer Zap to StrongEd as an editor, but I have only been able to compile through the StrongEd icons.

The StrongEd help does not seem to provide any info on how to view or access the compile commands it uses. I was hoping I would be able to see how it is compiling as i am having trouble from the command line.

Re: gcc and RISC OS

Posted: Sat Dec 15, 2012 10:34 pm
by Shawty
I'm not making any promises but if I get a chance, I'll fire things up and put some notes in here.

Re: gcc and RISC OS

Posted: Mon Dec 17, 2012 9:29 am
by nr.
If I go back to my trusty pi_css5 test case, I have a 'home' directory for the program: RISCOSpi.$.pi_css5_gcc. Within this directory, I have two subdirectories: 'c' containing the C files, and 'h' containing the header files. In both cases the files do not have any kind of suffix to the filename. The makefile then becomes:

Code: Select all

# Makefile for pi_fftcs5, Takuyo Ooura's
# Pi calculation for *nix or DOS
# Warning: this file has tabs in it.  It is required for GNU Make.
#
# This version may not produce optimal runs.  You'll need to experiment
# with the compiler options.

#Set this to your remove command.
RM= rm -f

#Set this to the proper math libraries to link against
MATH_LIBS= -lm

CC = gcc

#Set this to best optimization flags for your system. Defaults are for gcc.
CFLAGS = -Wall -pedantic -O -fomit-frame-pointer -funroll-loops

#Set compiler flags
CFLAGS += -march=armv6
#CFLAGS += -mfloat-abi=softfp
#CFLAGS += -msoft-float

#If you would like to minimize program output uncomment this line
#CFLAGS += -DQUIET_OUT

#Set this to important linker flags
LDFLAGS = -static

# Leave items below this point unchanged!

all: pi_css5


pi_css5 : pi_fftcs.o fftsg_h.o
$(CC) $(CFLAGS) pi_fftcs.o fftsg_h.o ${MATH_LIBS} ${LDFLAGS} -o pi_css5

pi_fftcs.o : pi_fftcs.c
$(CC) $(CFLAGS) -c pi_fftcs.c -o pi_fftcs.o

fftsg_h.o : fftsg_h.c
$(CC) $(CFLAGS) -c fftsg_h.c -o fftsg_h.o

clean:
${RM} pi_fftcs.o fftsg_h.o pi_css5


This allows me to use 'make' from the project directory to build the program, or 'make clean' to remove any objects. As you can see, I'm using 'rm' as part of the logic, so it depends on having !CoreUtils installed.

Ta,

Re: gcc and RISC OS

Posted: Mon Dec 17, 2012 5:37 pm
by pygmy_giant
Thanks nr - I will give this approach a whirl when I have the time, energy and presence of mind - full of winter bugs atm :¬\

Re: gcc and RISC OS

Posted: Sat Dec 22, 2012 10:51 pm
by pygmy_giant
Thanks again nr. - I adapted yout makefile and I am now getting errors and warnings, so things are being acknowledged and found - which is progress!

I have identified my problem as beeing two of the component files sharing the same header file, but it only being seen by one of them...

Re: gcc and RISC OS

Posted: Wed Jan 09, 2013 8:24 pm
by pygmy_giant
Well, after wasting hours of my life, I have given up on Make. I am not clever enough to use it.

I have instead found that I can instead just '#include' all the header and other relevant c files at the top of the main.c program and that the pre-processor will insert them as a direct text substitution for me.

Much simpler than trying to stitch them together with a makefile.

Think I'll leave Make to the experts.

Re: gcc and RISC OS

Posted: Wed Jan 09, 2013 9:01 pm
by Shawty
If it's any consolation, Iv'e never used Make, even back in the days when I was actually coding on Risc-OS full time using Norcroft C.

A couple of Obey Files, and some drag and drop to a few taskbar icons where all it took :-)

Re: gcc and RISC OS

Posted: Wed Jan 09, 2013 9:42 pm
by pygmy_giant
Thanks Shawty - that is some consolation :)

My code is for my robot's control system and I want it to run by default when the Pi is switched on - am I right in thinking that I need an obey file for that, or can I just drag the C object file into the 'run at start up' window? (too frightened to try incase it goes into spasm and locks me out).

Thanks in advance for any help.

Re: gcc and RISC OS

Posted: Thu Jan 10, 2013 12:43 am
by Shawty
Under Risc-OS making start up tasks run is not really that easy.

If you need it to run at start up and be part of the Multitasking side of the OS, then my advice to you is to create a "Relocatable Module"

If you look on your SD disk, inside the !Boot folder (Double click it with Shift Held Down to open a filer) you'll see there are many folders in there, and from memory there is a startup folder (Which may also be accessible to drag into from the configuration app)

However, this startup folder is really only designed to run tasks that you intend to perform some kind of task at start-up then quit straight away.

If your looking to provide a service program that interacts as an integral part of the OS, then creating it as a Relocatable Module that gets registered in !System is definitely the correct way, in fact the Risc-OS programmers Reference manuals strongly recommend that service style applications be created in this fashion.

You can register things like Toolbox / Window definition files and application sprites into the Resource File system (Same as is used by the inbuilt apps such as !Edit , !Draw etc) then just provide a very thin veneer over the top in the form of a simple UI that does nothing but make OS-Service calls to your apps module interface.

As for the exact mechanics of doing this using GCC, i can't help much there. Last time I did anything like that I was still using Acorns own Norcroft Compiler suite, Iv'e done very little so far with regards to using GCC, even under my Virtual Acorn emulator I have on the PC, as my Norcroft stuff still works :-)

You can download the Risc-OS PRM's (Full set) as PDF files from : http://foundation.riscos.com/Private/manuals/

If all you intend to do however, is control your robot using the PI, rather than boot into a desktop environment with a full OS, I would strongly suggest looking at going the Bare metal route.

This is something I'm exploring (Ironically to convert some of my old Acorn Risc-OS / Archimedies ARM Code sound and graphics demo's and games that Iv'e written over the years, over to the RPi)

You can implement singular startup code that is the only thing running on the device, It's a bit more work , but there Bare Metal forum on this site is full of great information, couple that with things like the Baking-PI course

http://www.cl.cam.ac.uk/freshers/raspbe ... orials/os/

and chuck in systems like "Dex-Basic"

http://www.dex-os.com/DexBasic/DexBasic.htm

and things couldn't be easier.

Re: gcc and RISC OS

Posted: Thu Jan 10, 2013 1:20 pm
by DavidS
pygmy_giant wrote:Thanks Shawty - that is some consolation :)

My code is for my robot's control system and I want it to run by default when the Pi is switched on - am I right in thinking that I need an obey file for that, or can I just drag the C object file into the 'run at start up' window? (too frightened to try incase it goes into spasm and locks me out).

Thanks in advance for any help.
Yow can open !Configure and fromthere Boot click on Run, and drag your application into that window, then click Set, then click set again. Now it will run that next time you reboot.

Some old users of RISC OS ma not know about this is this is a fairly new feature (at least I had not seen it until about a year ago).

Re: gcc and RISC OS

Posted: Fri Jan 11, 2013 12:50 am
by pygmy_giant
Shawty wrote:
You can implement singular startup code that is the only thing running on the device, It's a bit more work , but there Bare Metal forum on this site is full of great information, couple that with things like the Baking-PI course
Yep - deliberately avoiding that.

Will try the DavidS route first.

Thanks both.