Idiot meets libraries -> Pain!

BlitzMax Forums/BlitzMax Beginners Area/Idiot meets libraries -> Pain!

Picklesworth(Posted 2007) [#1]
In the last hour I have learned just how little I know about libraries and about using them with BlitzMax. Maybe you can help me!

I can get GTK popping in happily (I think) using code pulled from Brucey's gtkmaxgui module (his scary looking Imports in gtkcommon.bmx). The trouble is Importing anything else that I do not have an example of.

Unfortunately, I am a bit confused about the whole thing! I don't really know where to start with this question, so here is a list of various ignorant questions that have crept into my head in the last little while:

-(Kind of irrelevent): Does BlitzMax do shared libraries, or just static libraries?

-How can I get a library that BlitzMax can import, (for example) for libGlade?

-What's with those -mylibrary imports? I've used them before and I'm assuming that they are to link to a library in a way independent of the filesystem, but I have never really explored them. Does every library have a -something thingy defined? (What do I call those, anyway?). How can I find out how to import a library with that -blah thing?

I'll leave it at that for now, since likely the answers to those questions will solve my problems.


Brucey(Posted 2007) [#2]
Hallo Mr Pickles ;-)

Does BlitzMax do shared libraries?

Yes it does... sort of...

Only talking about Linux here so...

You use "-Lpath/to/lib" to tell it where to look for a library - if it isn't in the usual place.
You use "-lnameoflibrary" to link to the shared object. If the library is called "libblah.so" you would use "-lblah".

BMK is (or was... I forget since I've patched it so much) broken as far as linking to shared objects on OS X. (There is a tweaked version available - see my post in the tweaks for a link)

My Patched BMK also allows for CC compile time options, and LD link time options - which you will need for certain libraries that expect things set in certain ways.

On my FC6 I have a libglade-2.0.so

You would need to use the following to link to it :

Import "-lglade-2.0"

Anyways... the rest you should have fun working out for yourself ;-)
Some of my modules link to shared objects, the rest I tend to compile in the source. Some linky ones for Linux are GTK, Cairo, and Fontconfig. (might be more, but I lose track...)

Have Fun :-)


Brucey(Posted 2007) [#3]
But it's all trial and error mostly to begin with. I've been improving with every new module.

I had to learn C++ to do the Qt module - which was a bit of a learning curve, I can tell you... but it makes doing everything after that pretty much insignificant ;-)

These days it's finding a nice library to wrap that I have trouble with...


Brucey(Posted 2007) [#4]
more Linuxy information...

the environment variable LD_LIBRARY_PATH can hold a list of paths where the system should be able to find libraries.

ldconfig is a utility which you can list and add libraries to the system libs search list.
To get a list of all known libs :
ldconfig -p

To add a new library :
ldconfig -l [/path/to/lib/]libname

where the bit in square brackets would be optional if the library you want to add is in the current directory. ie. you can add a lib with either the full path, or relatively.

There is also a config file that keeps a list of paths (similar to LD_LIBRARY_PATH). You can find it at /etc/ld.so.conf
This file is a list of directories. You can add a new path to this file, and it will be one of the paths that ldconfig searches through...

HTH :-)


Picklesworth(Posted 2007) [#5]
Okay, it's on the right track! I'm getting error messages from libglade now, and they aren't even about linking errors :)

Thank you, Brucey. That is very helpful.


Picklesworth(Posted 2007) [#6]
*GASP*
Be glad, Glade is here!


Of course, it is completely non-functional at the moment, but it compiles and runs. (And it is more functional than most GUIs already, with resizing, stock icons, composite widgets and support for SVG images!)

Of course, this will also need some gtk stuff for some real functionality :(
I guess the best way to approach that is to not duplicate your efforts and instead to make sure this can talk to your gtkmaxgui module where necessary...

Gee, I'm using the GTK version of MaxIDE, too. That makes 3 times today you have helped me!

Edit:
Callbacks work! :)
LibGlade is now wrapped as far as I (or many other people, I hope) need. All I need to do at this point is some GTK stuff, which I fear is going to be a lot more troublesome.
(Oh, and some helper functions / actual objects would be good).