Automatic opening and closing of Libraries?

5 posts / 0 new
Last post
Reth
Reth's picture
Offline
Last seen: 11 years 8 months ago
Joined: 2011-07-09 22:16
Automatic opening and closing of Libraries?

Hi everybody,

currently I do all my AOS-coding in a (hopefully) AOS3.x compatible way. Thus I use OpenLibrary() and CloseLibrary() in order to make use of Lib-Functions for example from asl.library, graphics.library, intuition.library, gadtools.library, diskfont.library, layers.library and so on. I'm also always set __USE_INLINE__ as a Compiler flag (-D for GCC). I don't use IFaces or sth. else special in AOS4 at all.

Now I heard that this is not really necessary since when using #define __USE_INLINE__ switch every amigaos function will be considered as old os3.x function,
without special casting like IExec->function() or IIntuition->function(), what also means that all the stuff will open automatically, without needs of open the IFaces an so on. Usually together with that -lamiga and -lauto linking libs are added.

This confuses me a little bit. I'm wondering whether it is necessry to call OpenLibrary() and CloseLibrary() in order to use Libfunctions or not when coding under AOS4 (even in old AOS3.x/68k style)?

Maybe somebody here can shed some light on this?

Many thanks in advance and

Best Regards

kas1e
kas1e's picture
Offline
Last seen: 3 months 1 week ago
Joined: 2010-11-30 15:30
__USE_INLINE__ will take care

__USE_INLINE__ will take care about IFACE->function() casts, thats one deal

Added -lauto on the linking stage will take care about opening/closing of most libraryes, thats another deal.

I.e. __USE_INLINE__ itself do not mean that anything will opens automatically, but mean that no IFACE-> casts need it. And -lauto will take care about open/close libs (and can be used without __USE_INLINE__ pretty well, just with all that IFACE-> etc stuff).

Btw, sometime -lauto will not enough, and you will have errors about some functions from some libraryes: in that case you just need to add right #include <proto/protofile.h> to code).

Also it is no harm to just open them all in code manually, and its even "preffered" to have it like this and do not use -lauto. But still, i for myself all the time use it, just because its easy. More of it, i pretty offten open half of libs manually, and half of libs via -lauto, and open some libs which will cover -lauto: thats suck and mess, but works.

trixie
trixie's picture
Offline
Last seen: 6 months 3 weeks ago
Joined: 2011-02-03 13:58
Re: Automatic opening and closing of Libraries?

@Reth

I'm wondering whether it is necessry to call OpenLibrary() and CloseLibrary() in order to use Libfunctions or not

Of course it is always necessary to open a particular library before you use its functions! But you can use an autoinitialization code (the link library "libauto", via the -lauto switch) to open the libraries for you.

Still I'd recommend developing a habit to always open libraries manually. Usually it doesn't take more than writing an extra sourcecode file with library opening/closing stuff which you'll simply include in every project you make.

Reasons:

  • The -lauto switch only opens the most common libraries; you may have to open the rest manually (which somehow spoils the beauty of -lauto).
  • Manual opening gives you better library version control.
  • Manual opening allows you to implement meaningful, user-friendly error messages when the library fails to open. Whereas -lauto will just throw out some general message which the user may not find very helpful.

Personally, I only use -lauto for testing or implementing an idea quickly. When my programming itch actually turns into a proper application, I always open/close resources manually.

AmigaOne X5000-020 / 2GB RAM / Sapphire Pulse Radeon RX 560 / AmigaOS 4.1 Final Edition Update 2

walkero
walkero's picture
Offline
Last seen: 3 months 3 weeks ago
Joined: 2009-05-03 16:54
Re: Automatic opening and closing of Libraries?

If I am not wrong, with -lauto you can't set the minimum version of the library your program needs, so in case a user has an older library a requester will appear.

salass00
salass00's picture
Offline
Last seen: 6 months 2 weeks ago
Joined: 2011-02-03 11:27
@walkero That is the case

@walkero

That is the case with autoinit code generated by the current idltool.

It doesn't have to be that way though as f.e. with fd2pragma generated m68k library autoinit code you can set a minimum library version by simply defining a variable in your code:
unsigned long _ExpatBaseVer = 4;
If you don't define this variable one will be linked in for you with a value of 0.

Also nothing is stopping from checking the version after the fact by using the library base pointer. As a matter of fact if you need to check for a minimum revision as well as version then you have to it this way.

Log in or register to post comments