[Gambas-user] Distribution of custom shared libraries

Cedron Dawg cedron at exede.net
Sat Feb 23 15:46:48 CET 2019


[...snip...]

I didn't realise that you were talking about shipping a shared library with
your project. That changes matters substantially in that architecture does
make a difference. I've never done anything like that and it seems like the
IDE dialogs do not provide means for compiling C sources into shared objects
before packaging -- or cross-compiling options for that matter.

There might be ways to do it, but the most clean solution is a native
component, which is Gambas' term for gb.* components which are written
in C and directly connect the interpreter to some C-level interface.
These are not as easy to write as a C program or a Gambas component and
they have to be included in the Gambas source tree.

As I said, I have such a half-baked component on my computer (apparently
from 2015!). Maybe we should exchange ideas and turn your and my component
into something that can be included in the Gambas source tree. From that
point on, Linux distributions will take care of architecture dependency
when putting Gambas into their repositories. It will also free you from
worrying about receiving Structs from Extern functions. Native components
have a nicer way of making C-level data structures available to Gambas
programs.

I'm taking a look at your C file.

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk

===================================================================

I was half expecting to wake up this morning to find that gp.GamePad has been added to the latest release.  ;-)

Feel free to incorporate whatever you want.  You made me go back and look:  My original GamePad test program, from where I got the guts of the library, was done in the Fall of 2014.

I think having a gp.GamePad (or gp.GameDevice, or gp.JoystickDevice, or whatever) would make programming a lot more attractive to the young gamer crowd.  The game I wrote (still thinking of a good name for it) is meant to be a good starter template for beginning programmers to develop their own games.  I'm not a gamer at all, but I thought it was a good project for me to evaluate Gambas' capabilities.  The ease of interfacing to C code is a huge plus for me.

As to the original question, it would be really nice if there were a built in method through the IDE for .c shared libraries.  I would suggest that they get their own category and every library would have to be submitted with a Gambas demo program which shows how the functions are to be used.  Seeing as I only have a vague understanding of the whole packaging process, I haven't a clue how it should be done properly.

Finally, a note of caution about using the "#pragma pack(1)" directive, for those who may not know.  The reason the compiler pads a struct is to align multibyte values on appropriate addresses.  A two byte value should be aligned to even addresses, a four byte value to multiple of four addresses, and so on.  When you don't, the CPU has to do two memory fetches to get the value instead of one.  Unfortunately, on some architectures, it won't even work and you get a fault.  The lesson is if you use the pragma directive, and you are designing the struct, make sure those alignment rules are followed.

Thanks for looking at my code, I hope you like it.

Ced



More information about the User mailing list