[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Is it possible/acceptable to create a component in Gambas that depends on a shared library?


On Wednesday, February 11th, 2026 at 22:43, Lee <t.lee.davidson@xxxxxxxxx> wrote:

> On 2/11/26 12:00 PM, gbWilly wrote:
> > On Tuesday, February 10th, 2026 at 22:49, Lee <t.lee.davidson@xxxxxxxxx> wrote:
> >
> >> On 2/10/26 3:06 PM, gbWilly wrote:
> >>> A lot of the questions you pose here Claus have my attention as well. I'm very curious to read answers to these questions as I do want to experiment with interfacing with some C libraries myself.
> >>
> >> Hi Willy,
> >>
> >> Are you interested in interfacing with a shared library directly from Gambas using the "LIBRARY" and "EXTERN" declarations?
> >> Or, are you interested in creating one or more components that interface with a shared library using the Gambas Programming
> >> Interface (https://gambaswiki.org/wiki/dev/api)?
> >>
> >
> > Just getting an application interface with a library would be where I would like to start. I know nothing on the matter, but I am curious.
> >
> > gbWilly
> 
> Understood. You're probably already aware of the "how to" at https://gambaswiki.org/wiki/howto/extern, but I mention it just in
> case. Perhaps that is a bit too complex for your preference at the moment. I admit that I haven't fully read it.
> 
> I have attached a very simple project that uses six functions from "Libc:6". I got the 'perror' function from [1] and the rest
> from [2].
> 
> This example may be too simple as, for example, one thing it does not demonstrate is how to handle a callback, ie. using an
> external function that expects a callback function as one of its arguments. Gambas makes this quite simple.
> 

Thank you very much for this. The code combined with the link to the library documentation is very useful for me to wrap my head around it all. 

You did use Exec "getuid" for the first 4 functions in your example.
I changed this, because, even though the result happens to be the same, it seems you need to Exec 3 other functions from the library instead for the last 3 functions (see red marked section on screenshot). Is my assumption there correct?

I also managed to use a simple function like basename and interface with it (see yellow marked section on screenshot).

A good place to start learning some stuff this libc, combined with what is on the wiki.

Fun stuff to play with.

Thanks,


gbWilly

GambOS
Gambas3 for Debian/Ubuntu

...there is always a Catch if things go wrong!

Attachment: post.png
Description: PNG image