C programming


21 posts
by skywalker » Sun Jan 06, 2013 9:22 pm
I see some people here trying to get started with C programming. That's what I would like to do as well, but at the moment it looks like a minefield.

There are lots of questions:
- What is the actual state of play of C complier suites on RISCOS? Which tools are considered canonical (or 'best')?
- For something so important (encouraging the community to start writing more software for the platform) I'm surprised to find none of the package managers seem to offer any C tools on the Pi. Various old web sites make claims, such that gcc is available with RiscPkg, but I've installed all the package managers I can find and still don't get offered a C compiler as far as I can see. Perhaps this is because the hardware platform is still new and the compilers haven't been validated on the RPi yet?
- It looks like some people are making progress with a manual "hunt and peck" installation. I could do the same I suppose, reading the various hints from forums like this, but it would be great if someone could publish a complete HOWTO on setting up a correctly working compiler from scratch. Like others, I'm unfortunately currently in a position of having fairly low knowledge and confidence in the system as a whole, so can't always infer what I'm doing wrong, or correctly interpret certain hints. Is anyone here in a position to make such a HOWTO, or at least a simple series of steps for a working installation?
- I have read certain things about common libraries for developing on RISCOS, such as UnixLib. It's probably the case that one or more of these libraries have become common stock for C programmers. Can anyone explain what libraries are typically used and where to get the latest versions? As well as foundation libraries, I'd be interested in a good GUI/WIMP framework for C.

Obviously, I'm motivated by trying to save myself time scrabbling around and possibly going down a lot of blind alleys before finally arriving at the 'correct' recipe for an up-to-date installation of tools and libraries. However, I'm convinced that any robust set of installation steps would be highly valuable time and again as others seek to get started.
Posts: 28
Joined: Tue Nov 06, 2012 4:55 am
Location: Vancouver, Canada
by DavidS » Sun Jan 06, 2013 10:02 pm
What do you by 'installed all of the package managers I could find' ?
As far as I know there is only RISCPkg, and that is included on the SD card of RISC OS for the Pi. RISCPkg does list gcc.
ARM Assembly Language: For those that want: Simple, Powerful, Easy to learn, and Easy to debug.
User avatar
Posts: 1251
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
by colin B » Sun Jan 06, 2013 11:41 pm
It isn't exactly 'C' more like a hybrid of C/Pascal but there is Charm, which I'm about to start playing with.
It is pre-installed in the RISCOS image.
On a clear disk one can seek forever
Posts: 119
Joined: Sun Mar 04, 2012 12:23 pm
by skywalker » Sun Jan 06, 2013 11:50 pm
DavidS wrote:What do you by 'installed all of the package managers I could find' ?
As far as I know there is only RISCPkg, and that is included on the SD card of RISC OS for the Pi. RISCPkg does list gcc.


What I meant was that I knew I had Packman and Store and went looking for others. RISCPkg was mentioned in association with gcc so I installed this. I then noticed that gcc was not in the list of packages.

Your reply caused me enough self-doubt to recheck a few things:
1. I still can't see where the included copy of RiscPkg is. I have the Oct 31 distribution of RISCOS for the Pi, which I assume is still the latest, but perhaps that has been superseded. I'm pretty sure I've navigated through all the Apps directories in my search.
2. I had assumed that the packages displayed in the RiscPkg I downloaded were up-to-date, but I just did an "Update" and lo! the displayed package list is quite different. Moreover it now includes a "GCC".

So, I think I'm off to the races now. Back to the Raspberry Pi bat cave to see if "GCC" installs nicely now...

Thanks!
Posts: 28
Joined: Tue Nov 06, 2012 4:55 am
Location: Vancouver, Canada
by colin B » Sun Jan 06, 2013 11:56 pm
[quote="skywalker1. I still can't see where the included copy of RiscPkg is. [/quote]


On the current image (the one on the Pi download link) the package manager is on the desktop by default.
On a clear disk one can seek forever
Posts: 119
Joined: Sun Mar 04, 2012 12:23 pm
by skywalker » Mon Jan 07, 2013 12:05 am
colin B wrote:It isn't exactly 'C' more like a hybrid of C/Pascal but there is Charm


Indeed. This looks like a nice piece of work: full suite of tools, easy to start, nice integration. Also, I like the syntax and the compilation speed is great.

Plain old C may not be a terribly convenient/productive nor modern language to use (though that's clearly in the eye of the beholder), however it is something of a lingua franca. It's pretty handy to be able to move plan old C from other platforms/locations where this isn't dependent on any special platform features.

I'm going to play with (and probably use) both C and Charm, certainly while I'm finding my feet on RISCOS.

BTW, I've found a lot of interesting references to other languages on RISCOS: Ada, Forth, ML etc. Sadly, most of the web links to actual content are dead.
Posts: 28
Joined: Tue Nov 06, 2012 4:55 am
Location: Vancouver, Canada
by skywalker » Mon Jan 07, 2013 12:16 am
colin B wrote:On the current image (the one on the Pi download link) the package manager is on the desktop by default.


I see "PackMan" on my desktop, but not "RiscPkg", which is what I've seen mentioned in web content and discussions as the source of the GCC package.

However, I think there is some coupling between the two. I just went to PackMan again and did a head-palm when I saw the GCC package listed. How could I have missed that? However, with all this uncertainty swirling around, I did an "Update Lists" in PackMan - and now the GCC package has disappeared again.

So, I think my confusion is partly due to PackMan and RiscPkg sharing the same package database on my Pi, but loading package lists from different sources. Indeed, I've just opened RiscPkg again and the GCC package is now gone.

What fun :-)
Posts: 28
Joined: Tue Nov 06, 2012 4:55 am
Location: Vancouver, Canada
by johnha » Mon Jan 07, 2013 12:43 am
Hi All,

I'm new to RISC OS and gcc but have (after some head scratching) managed to get gcc running on RISC OS Pi. I don't know if this is the most stable/efficient/safest way of doing it, but it does seem to work:

I used the following forum url's to do this:
http://www.raspberrypi.org/phpBB3/viewtopic.php?t=22783&p=21797 - installing gcc and some notes about RISC OS filenames.
http://www.raspberrypi.org/phpBB3/viewtopic.php?f=55&t=21184&start=125 - something about wimpslot 6000K.

Steps I used:
1) I already had the 'UnixSharedLibs' (which I believe are required) when I installed Perl from !Packman.
2) Download 'gccsdk-gcc-core-bin.zip' from http://www.riscos.info/downloads/gccsdk/latest/ - or it sounds like you can install this from RiskPkg (which I couldn't find).
3) Extract the zip into the Apps/Development folder.
4) Merge the !System folder - Middle click the Raspberry icon on the right of the task bar and select Configure which opens a window, drag the !System folder to the window and click 'Merge'.
5) Double-left-click the !GCC icon - I believe this sets up the path to the compiler.
6) Shift-double-left-click the !GCC icon - this opens the !GCC directory in a window.
7) Create a 'myproj' folder in the !GCC directory and create folders for source 'c' and object files 'o' inside this. Copy the 'helloworld' file from the Example/C/c directory in the zip to myproj.c (the 'c' directory under 'myproj').
8) Open a Task Window (from the Raspberry icon on the task bar).
9) Navigate to the Apps.Development.!GCC.myproj directory (DIR $.Apps.Development.!GCC.myproj).
10) Type 'gcc -v' - displays the GCC version - results in an error stating that the program needs 6000K to run.
11) Type 'wimpslot 6000K' - which fixes the above problem, and then 'gcc -v' should report version information. I have no idea what this does only that it works!
12) To compile 'helloworld' type 'gcc c.helloworld -o o.helloworld' - which should create an executable 'helloworld' in the 'myproj.o' directory.

I hope this helps, I don't really understand it all or whether it works for more advanced coding than very simple input/output.

John.
Posts: 2
Joined: Sun Jan 06, 2013 11:55 pm
by skywalker » Mon Jan 07, 2013 1:00 am
OK, I think I have "GCC" installed (with its dependencies and "GCC Common", which isn't a dependency but the description made it seem important). Also grabbed "Make".

Given that these do not appear in the list presented to me normally in PackMan, I had to refresh the package list in RiscPkg first. I then considered just using RiscPkg to do the installing, but given that PackMan is the normal tool and apparently recommended tool for this on the RPi distro, I decided to risk using that tool instead - seeing as it was now showing the requisite packages.

Indeed, PackMan appears to have installed everything with no errors. Although most of the programming packages are installed into $.Programming, !GCC and !Make appear to have been installed into $.Apps.Programming, but that's fine.

OK... now to see if HelloWorld.c will build...
Posts: 28
Joined: Tue Nov 06, 2012 4:55 am
Location: Vancouver, Canada
by skywalker » Mon Jan 07, 2013 1:11 am
johnha wrote:Steps I used:

Thanks John, that's exactly what I was hoping for.

So, I seem to be the point where I've installed the tools (albeit using some odd combination of package managers, rather than your manual download/extraction).

I'm curious about putting the project directory and source files within the GCC application directory. I was going to try making a projects directory elsewhere, with a helloworld project and its child source directories. I'll try that first and then I have your known-to-work steps to fall back to if that fails.

The wimpslot step would no doubt have snagged me, so I'm gratefully for that bit of lore!
Posts: 28
Joined: Tue Nov 06, 2012 4:55 am
Location: Vancouver, Canada
by johnha » Mon Jan 07, 2013 1:21 am
Hi skywalker,

I have been able to put the 'myproj' directory in the '$.Apps.Development' directory (at the same level as !GCC) and the gcc path appears to still work (although I know nothing of paths on RISC OS). I haven't tried moving it 'further away' yet.

I think the double-left-click of the !GCC icon is needed after every boot, and the 'wimpslot 6000K' is needed every time you open a new task window (from experiment). I presume there may be a way to set these to happen on boot-up?

John.
Posts: 2
Joined: Sun Jan 06, 2013 11:55 pm
by skywalker » Mon Jan 07, 2013 2:04 am
Well, I can report that gcc -v works. I didn't even need to do the "wimpslot" thing - which according to the help sets the reserved application space (heap?) allocated to the next task that is started.

However, when I try to compile my C file (a quick 'helloworld' C source, because apparently my package-manager installed GCC directory doesn't include the Examples directory), I get:

SDFS::RISCOSPi.$.Apps.Programming.!GCC.bin.gcc: Internal compiler error: program ld got fatal signal 33

That seems to happen irrespective of double-clicking the !GCC directory icon or running wimpslot (in various amounts, including much larger than 6000K).

So, I think I'm stymied for a bit. I'll try more RTFM.
Posts: 28
Joined: Tue Nov 06, 2012 4:55 am
Location: Vancouver, Canada
by skywalker » Mon Jan 07, 2013 4:53 am
So, next I uninstalled all the GCC stuff (GCC, GCC-2.95, CPP, CPP-2.95) and Make, and then generally tidied up (residual experimental directories) to attempt to get back to a base state.

Instead of installing packages via PackMan (with the aforementioned package list built by RiscPkg!), I unpacked gccsdk-gcc-core-bin into $.Apps.Programming, and followed your steps exactly.

When I got to the merging of the System directory I figured you meant to run the System config utility, which seems right as this accepts a drop and has a Merge button. I'm curious what this does though as I note the !System folder in the expanded gcc distribution has a "310" directory, which sounds like its intended for the Archimedes 310, but maybe it works on all platforms since.

Anyway, when I got to testing "gcc -v" at the command prompt, I got the error:
File 'SharedLibs:SOM1stRun' not found

However, there's a "!SharedLibs" directory in this distribution at the same level as !GCC, so I figured that was worth a double-click. Sure enough, that results in a working "gcc -v" (again, no need to 'wimpslot' so far for me).

I notice that the message printed by gcc -v is vastly more verbose than when I did the same in the package-manager installed GCC. I now get a whole list of configuration information, as well as the gcc version (reported as 4.1.2 Release 2).

A simple "gcc c.helloworld" in my project directory (which btw is in a completely different part of the directory hierarchy to the GCC installation) then resulted in a working a/out file in the current (project) directory.

So I now have a working gcc system (at least to some level). Hurrah!

It's tempting to make the following conclusions from my experiments:
1. My downloaded RiscPkg and the 'standard' PackMan interact in a potentially bad way by apparently sharing local data, but getting their package lists from different servers (which serve different packages too).
2. The GCC versions, or at least configurations, of the two approaches (package-manager installation vs manual installation) seem different.
3. Just using the package-managers in the way I did was insufficient to arrive at a working version of the compiler suite. The resulting 'Fatal error 33' might have been recoverable I suppose, but certainly I have no idea what that means and therefore no way to even guess at what components might be missing or misconfigured.

Based on experience, my amended version of your steps is:
[0) I already had the 'UnixSharedLibs' (which I believe are required) when I installed Perl from !Packman.]
1) Download 'gccsdk-gcc-core-bin.zip' from http://www.riscos.info/downloads/gccsdk/latest/
2) Extract the zip into the Apps/Programming folder (this being the place where package managers choose to locate GCC)
3) Merge the !System folder - Middle click the Raspberry icon on the right of the task bar and select Configure which opens a window, double-left-click to open the "System" utility, drag the !System folder from Apps/Programming to its window and click 'Merge'.
4) Double-left-click the !GCC icon - I believe this sets up the path to the compiler.
5) Double-left-click the !SharedLibs icon - I believe this sets up libraries used by the compiler.
6) Create a 'myproj' folder in a directory of your choice and create folders for source 'c', headers 'h' and object files 'o' inside this. Copy the 'helloworld' file from the Example/C/c directory in the zip to myproj.c (the 'c' directory under 'myproj').
7) Open a Task Window (from the Raspberry icon on the task bar).
8) Navigate to your myproj directory (DIR $.<your path>.myproj).
9) Type 'gcc -v' - displays the GCC version along with current configuration information.
At the time of writing the reported version of the gcc wrapper is 2.1.4 Release 2.
10) If instead of the configuration and version information you receive an error about the amount of memory needed to run gcc then type 'wimpslot 6000K' - which should fix the problem, and then 'gcc -v' should report version information. wimpslot sets up the memory allocated to the next task to be executed.
11) To compile 'helloworld' type 'gcc c.helloworld' - which will result in an executable file called 'a/out' in the current directory ('myproj'). Alternatively, type 'gcc c.helloworld -o helloworld' to produce the appropriately named executable in the current directory.
Posts: 28
Joined: Tue Nov 06, 2012 4:55 am
Location: Vancouver, Canada
by skywalker » Mon Jan 07, 2013 5:51 am
OK... one final update (?)

After getting this all to work, as documented in this thread, I then decided that I should return to the 'native' PackMan package listing, rather than using the RiscPkg ones (that may or may not work properly). Hence another "Update Lists" in PackMan. Then, I decided to install Make, which is visible in the package list there, unlike gcc. However, this installs into Apps.Development, rather than the RiscPkg perference for gcc which seems to be Apps.Programming.

Now that I'm 'back' in the PackMan world, with a manually installed gcc, it seems better to adopt the PackMan convention, so I renamed my Apps.Programming directory to Apps.Development. At that point it came as no surprise that gcc stopped working (claiming that it couldn't find the path via "Apps.Programming". I tried double-clicking !GCC and !SharedLibs again, but they apparently don't overwrite with new path configuration, so I figured I'd need to reboot.

After rebooting, I double-clicked !GCC and !SharedLibs and then attempted to do 'gcc -v' again. THIS time I got the memory warning about requiring a minimum of 6000K. So, I can only assume that something I had done in my prior session had avoided the need for this step, but it does look like it will be a 'feature' of my use of gcc going forward.

There's are really big holes in my RISCOS knowledge concerned with modules, the filer, and how 'paths' work, along with other configuration. I can see certain behaviours, including configuration that seems transient and limited to a desktop session - but I currently have no idea what's behind the curtain, nor how one is supposed to make things like the paths to GCC and its libraries, or the memory requirement for gcc, stick between sessions.

So anyway, again editing the HOWTO steps:
[0) I already had the 'UnixSharedLibs' (which I believe are required) when I installed Perl from !Packman.]
1) Download 'gccsdk-gcc-core-bin.zip' from http://www.riscos.info/downloads/gccsdk/latest/
2) Extract the zip into the Apps.Development folder (this being the place where PackMan chooses to locate dev tools)
3) Merge the !System folder - Middle click the Raspberry icon on the right of the task bar and select Configure which opens a window, double-left-click to open the "System" utility, drag the !System folder to its window and click 'Merge'.
4) Double-left-click the !GCC icon - I believe this sets up the path to the compiler.
5) Double-left-click the !SharedLibs icon - I believe this sets up libraries used by the compiler.
6) Create a 'myproj' folder in a directory of your choice and create folders for source 'c', headers 'h' and object files 'o' inside this. Copy the 'helloworld' file from the Example/C/c directory in the zip to myproj.c (the 'c' directory under 'myproj').
7) Open a Task Window (from the Raspberry icon on the task bar).
8) Navigate to your myproj directory (DIR $.<your path>.myproj).
9) Type 'gcc -v' - displays the GCC version along with current configuration information.
At the time of writing the reported version of the gcc wrapper is 2.1.4 Release 2.
10) When running gcc for the first time in a RISCOS session, you may receive an error about the amount of memory needed to run gcc. If so then enter the command 'wimpslot 6000K' right before then command 'gcc -v'. This should set up the memory configuration and then gcc should report version information as expected.
11) To compile 'helloworld' type 'gcc c.helloworld' - which will result in an executable file called 'a/out' in the current directory ('myproj'). Alternatively, type 'gcc c.helloworld -o helloworld' to produce the appropriately named executable.
Posts: 28
Joined: Tue Nov 06, 2012 4:55 am
Location: Vancouver, Canada
by DavidS » Mon Jan 07, 2013 12:28 pm
Ok I have looked up PackMan. PackMan is ROOL's package manager, and RiscPkg is the community package manager.

I have seen no problems with software installed with RiscPkg, though it sounds like it is installing something that is not ARMv6 clean. This seems odd as the ARMv6/7 compatibility list on the ROOL site points to the RiscPkg page for GCC.
ARM Assembly Language: For those that want: Simple, Powerful, Easy to learn, and Easy to debug.
User avatar
Posts: 1251
Joined: Thu Dec 15, 2011 6:39 am
Location: USA
by SEDev » Mon Jan 07, 2013 1:21 pm
DavidS wrote:Ok I have looked up PackMan. PackMan is ROOL's package manager, and RiscPkg is the community package manager.

No, PackMan and RiscPkg are both front-ends for the same package system. RiscPkg is older and development seems to have stopped, PackMan is more recent and is still actively being developed. This is probably the reason why ROOL went for PackMan, and I strongly recommend that you stay with that.

Both use the same sources for their packages. If the list of packages they offer differs then, presumably, their configured package sources differ. In PackMan you can see its sources using Iconbar-menu -> Advanced -> Sources.

For RiscPkg things are a bit less user-friendly as you'll need navigate to its choices directory: !Boot.Choices.RiscPkg . Comparing the two sets of sources should show why one offers GCC and the other doesn't.

You may also want to look at the information on the ROOL site:

RISC OS packaged software
http://packages.riscosopen.org/packages/

PackMan User's Guide
https://www.riscosopen.org/wiki/documen ... 's%20Guide

RISC OS Packaging Guide - How to make packages for RISC OS
https://www.riscosopen.org/wiki/documen ... ng%20Guide

When installing GCC manually from http://www.riscos.info/downloads/gccsdk/latest/ do not put it in Apps.Development as it doesn't have the control files that the package manager requires to identify the package and check for updates.

If you use PackMan to install then, after installation, you can put a stub application (basically a shortcut) anywhere you like. To do this select the package in PackMan's main window, click Menu (middle mouse button) over it and choose: Package <package name> -> 'Apps..'.

In the window that appears click Menu over the application then Apps <App name> -> Create stub -> dialogue box. Drag the icon from the dialogue box to where you want the stub. To run the application you can now just double-click the stub.

If you want GCC to be available from start-up then open Configure, click on Boot, then Run and drag GCC (or its stub) to the scrollable list. Click Set when done. Now GCC will be run each time the machine is booted.
Posts: 24
Joined: Thu Aug 02, 2012 10:55 pm
by microbitsuk » Mon Jan 07, 2013 1:24 pm
have a look at http://www.reallysmall.co.uk/Pages/norm ... rcery.html
all you will need and more.
If you have some spare cash then buy Nutpi from the ROOL web site it includes
the full C/C++ development suite an lots more for 35 pounds + P&P link below
https://www.riscosopen.org/news/article ... spberry-pi
Posts: 33
Joined: Fri Sep 09, 2011 10:04 am
Location: Perth WA
by NigelJK » Mon Jan 07, 2013 8:10 pm
As above. I installed from Pi Nut and after a little reading had it compiling the samples using the GUI tool.
Posts: 64
Joined: Wed Sep 05, 2012 1:44 pm
by pygmy_giant » Mon Jan 07, 2013 11:39 pm
Posts: 1566
Joined: Sun Mar 04, 2012 12:49 am
by skywalker » Tue Jan 08, 2013 6:26 am
microbitsuk wrote:If you have some spare cash then buy Nutpi from the ROOL web site


Funny that. I've had a Nut Pi for weeks - I bought it mostly as a way to support ROOL (especially when I found their donation mechanism was broken, now fixed) and figured 'I might eventually find something useful on it'. I had perused ROOL's Nut Pi page, but had no idea it had a C/C++ development suite per se. "Desktop Development Environment" sounds interesting, but when you click on the link for it on the ROOL Nut Pi page it takes you to a promo page instead of a description of what DDE actually is.

So, that's probably a nice way for me to get set up with a decent development environment.

However, I really think the most essential of all development tools (C compiler and SDK/platform libraries) should be available free via a couple of clicks in the platform package manager - if not actually preinstalled like Charm is. Any obstacles to people starting to write useful applications on a platform is arguably a bad thing for the future of the platform, even for technically competent developers who can probably 'muscle through'. Of course I'm just going by the fact that I still don't see GCC in my PackMan package list for some reason, though the fact that most people seem to be manually installing it suggests that nobody is (yet). Anyway, just sayin'...as they say.
Posts: 28
Joined: Tue Nov 06, 2012 4:55 am
Location: Vancouver, Canada
by pygmy_giant » Tue Jan 08, 2013 11:34 pm
Perhaps there should be a wish list thread for packages to be pre-intalled in the next release?

Anyone successfuly queried Datapower in NutPi with the pre-installed php?
Posts: 1566
Joined: Sun Mar 04, 2012 12:49 am