A couple of queries...


10 posts
by Jamdog » Mon May 28, 2012 8:22 pm
I got my Pi this morning in the post, installed the recommended Debian image, wrote a simple 'Hello World!' program in C, then used the Geany program (which came with the OS image) to make/build it.

As someone who has very limited Linux knowledge, I'm feeling like a bit of a noob, but pleased with getting my first Pi program to compile and run within an hour of turning it on. I even started a blog on the subject.

I am an old fashioned C coder, but one thing I'd like to know is what are the capabilities of Geany? Can it compile C++ or even other languages? The website for it only really tells me it's capabilities as a text editor...

Another question I wanted to ask was regarding the Pi's 256Mb memory. I remember in the early days of MS-DOS-based computing creating 'RAM Disks' (portions of memory used as a small hard-drive) and the reverse, virtual memory (using disk space as extra memory). Can this be done on the Pi - I have a 16Gb SD Card, and it would be great to be able to use 1Gb or so of it as extra 'memory' for my programs.
Posts: 2
Joined: Mon May 28, 2012 8:05 pm
by chmurli » Mon May 28, 2012 8:59 pm
You can configure Geany by:
- open file with certain extension (eg .c, .cpp etc.).
- build -> set build commands
- set appropriate flags and libraries for compilation

Remember that this setting are store only for files with same extension. You have to configure this for each extension (of course if you would like to work with various languages).

Its not recommeded but you can make swap partition (or file) to extend memory on raspberry pi.
https://wiki.archlinux.org/index.php/Swap
Like I said - not recommanded. Your sd card will be propably exhausted very soon.
Posts: 8
Joined: Sat May 19, 2012 8:38 pm
by annodomini2 » Tue May 29, 2012 8:57 am
If you look at SSD performance, most will be advertised with peak sequential transfer speeds.

Same with SD cards.

However the critical element for most users is the IOPs and 4k random read/writes.

For this, SD cards are very very poor, they are designed for basic data storage, the flash used in them is not optimal in being an OS operating device.

You can setup a swap file, but it will be slooowww!
Posts: 33
Joined: Sun Feb 05, 2012 12:00 am
by Mjiig » Tue May 29, 2012 10:00 am
It's worth bearing in mind that geany doesn't build anything itself, it really is only a text editor. However it does have the ability to run other commands that do build your programs for you, usually GCC or G++ (a front end for GCC). With the appropriate build commands set up (as explained above by chmurli) you can build (or run in interpreted languages) just about anything using Geany.
Posts: 21
Joined: Mon Dec 05, 2011 8:44 pm
by Narishma » Tue May 29, 2012 4:18 pm
Jamdog wrote:The website for it only really tells me it's capabilities as a text editor...

That's because it's just a text editor. It doesn't build anything, it just calls an external compiler for you (GCC in this case but you can configure it to call whatever program you want).

To compile you program directly you can do
Code: Select all
gcc test.c -o test
, then you can run it with
Code: Select all
./test
Posts: 150
Joined: Wed Nov 23, 2011 1:29 pm
by Jamdog » Wed May 30, 2012 11:56 am
Thanks for the replies...

I'd actually tried to compile from the bash prompt, and got the message:
bash: bcc: command not found.

Of course, now I realise I'd tried the bcc command, not gcc... :oops:

If Geany will do much of the work for me, I'm tempted to just use that instead. Not sure how it will handle larger multiple-C-file projects yet, but I'll enjoy playing...

My son's first question was 'Will it run Minecraft?'. :roll:

I plan on using it to teach him C, as it's the language I know best, and will give him a good basis for many other languages. He will, however, complain if it can't be used for a little downtime fun. Can anyone recommend good games that a (mature) 10-year-old might enjoy, that would run on it?
Posts: 2
Joined: Mon May 28, 2012 8:05 pm
by Pickle » Wed May 30, 2012 1:53 pm
supertux
Posts: 64
Joined: Tue Sep 20, 2011 5:09 pm
by robthebloke » Wed May 30, 2012 2:33 pm
Jamdog wrote:Not sure how it will handle larger multiple-C-file projects yet, but I'll enjoy playing...


I'd point out that if you want to compile C++ code, you need to use g++ instead of gcc. (I usually compile C files as C++, since it's a little less restrictive in the syntax allowed).

With gcc, using multiple source files involves compiling each *.c file into it's own object file (*.o) using the -c flag for gcc. A little example:

myHeader.h
Code: Select all
// This isn't stricly C++, but it works on most compilers (eg gcc, MSVC, Intel).
// It's a slightly simpler way of preventing this header file being included more than once
#pragma once

// declare any function prototypes or global variables with the extern keyword
extern void myFunc();


mySource.c
Code: Select all
#include "myHeader.h"
#include <stdio.h>
void myFunc()
{
  printf("Hallo!\n");
}


main.c
Code: Select all
#include "myHeader.h"
int main()
{
  myFunc();
  return 0;
}


To compile and link 'myApp', you should be able to run the 3 following commands:
Code: Select all
> gcc -c main.c
> gcc -c mySource.c
> gcc -o myApp main.o mySource.o


Doing that will quickly become extremely tedious. To simplify things you will want to create a 'makefile'. (This is slightly nicer because it sets up dependencies, which means it will only rebuild those files that have changed). If you save the following text as a file called 'makefile', and put it in the same directory as your source.....

Code: Select all
# high level make rule
all : myApp

# myApp depends on main.o and mySource.o
myApp : main.o mySource.o
   gcc -o myApp main.o mySource.o

# main.o depends on main.c
main.o : main.c
   gcc -c main.c

# mySource.o depends on mySource.c and myHeader.h
mySource.o : mySource.c myHeader.h
   gcc -c mySource.c

# a 'clean' rule. To use, type the command  'make clean'  into the command prompt. This
# will delete all temporary build files (i.e. the objects).
clean:
   rm *.o myApp


From the command prompt, typing 'make' should now cause the code to be compiled and linked into a single executable.... From a quick look at the Geany docs, it looks like you should be able to call that makefile from the build menu.
Posts: 8
Joined: Fri Mar 09, 2012 1:30 pm
by Narishma » Wed May 30, 2012 6:44 pm
robthebloke wrote:[snip]

I think he was talking about using Geany with a multi-file project.
Posts: 150
Joined: Wed Nov 23, 2011 1:29 pm
by Mjiig » Wed May 30, 2012 8:18 pm
Jamdog wrote:If Geany will do much of the work for me, I'm tempted to just use that instead. Not sure how it will handle larger multiple-C-file projects yet, but I'll enjoy playing...

Although it can be a pretty big investment to get used to, for projects larger than 3 or 4 files I would seriously recommend you throw together a makefile, and just set geany (or whatever you're using) to call make. Doing this decreases build times on big projects when you make small changes and can reduce a complex set of commands to 4 letters when you're using the terminal not an IDE.
Posts: 21
Joined: Mon Dec 05, 2011 8:44 pm