Some newlib dummys questions

12 posts / 0 new
Last post
LyleHaze
LyleHaze's picture
Offline
Last seen: 2 years 2 weeks ago
Joined: 2011-05-26 03:58
Some newlib dummys questions

I understand that we have an underlying clib2 or newlib, which support lots of the lower level "stuff". and I am being vague because I have no more details than that.(file handles? linkage to parents? )
I understand that certain programs, such as tools for Bars&Pipes, or AHI drivers, or auto-starting USB FD drivers often link with "-nostartfiles", which leaves out the clib2 or newlib code and initialization. I think this applies to many libs and devs as well.

I am absolutely sure of NOTHING I have said so far. This is a learning process for me.

Now assuming I am writing, for example, an autostarting usbfd driver, which will be launched automatically when a matching bit of hardware is plugged in.
I can open DOS, Exec, and whatever else I need using the usual methods.

But what about newlib?

Is there a good way to do this? Do I simply open newlib.library and INewlib? is there any other special initialization that I need to do, or are some things forbidden if I opened it myself?

I'm just trying to understand the difference between newlib and the more common libraries we use. Any information would be quite helpful.

Thanks,
LyleHaze

salass00
salass00's picture
Offline
Last seen: 6 months 1 week ago
Joined: 2011-02-03 11:27
Re: Some newlib dummys questions

Just open newlib.library in libInit() and close it in libExpunge().

  1. NewlibBase = IExec->OpenLibrary("newlib.library", 53);
  2. INewlib = IExec->GetInterface(NewlibBase, "main", 1, NULL);
  3. if (INewlib == NULL) {
  4. IExec->Alert(AG_OpenLib | AO_NewlibLib);
  5. goto error;
  6. }
  1. IExec->DropInterface(INewlib); INewlib = NULL;
  2. IExec->CloseLibrary(NewlibBase); NewlibBase = NULL;
trixie
trixie's picture
Offline
Last seen: 6 months 3 weeks ago
Joined: 2011-02-03 13:58
Re: Some newlib dummys questions

@LyleHaze

What salass00 says. I use newlib in my BOOPSI classes all the time (classes are libraries and as such are linked with -nostartfiles, too).

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

LyleHaze
LyleHaze's picture
Offline
Last seen: 2 years 2 weeks ago
Joined: 2011-05-26 03:58
Re: Some newlib dummys questions

Thank you both.
Learning as I go, and I wouldn't have it any other way. :)

LyleHaze

hypex
hypex's picture
Offline
Last seen: 3 months 3 weeks ago
Joined: 2011-09-09 16:20
Re: Some newlib dummys questions

Lyle check out this thread where I ran into trouble using -nostartfiles with Newlib. In case you run into the same. It is informative though for some reason has some negative energy whatever that is about.

The main difference between CLib and Newlib is that CLib is a static link library and Newlib is an Amiga shared library. Also Clib is easier to deal with when using -nostartfiles as the following thread would demonstrate:

http://www.os4coding.net/forum/failing-create-library-file-object-last-step

broadblues
broadblues's picture
Offline
Last seen: 4 years 9 months ago
Joined: 2012-05-02 21:48
Re: Some newlib dummys questions


Also Clib is easier to deal with when using -nostartfiles as the following thread would demonstrate:

No , it is not , when creating a clib2 based library you have to write custom code to replace the contsructor / destructor calling that sets up the various library components, and these components won't be the same as the program calling the library you are creating.

Newlib is a much better and simpler solution for libraries as it requires no constructor code in the library just the creation and initialisation of the INewlib interface. Newlib calls are then called in the context of calling program so stdio etc can be used from the library safely (though you wouldn't ofte want to).

LyleHaze
LyleHaze's picture
Offline
Last seen: 2 years 2 weeks ago
Joined: 2011-05-26 03:58
Re: Some newlib dummys questions

Hypex, Broadblues,
Thanks, that was an interesting read.
Especially after today at work, I can appreciate that different programmers bring different perspectives. I'm not taking sides, just taking notes.

I count myself fortunate that I am able and willing to learn.

At the moment I have an autostarting fd that is making the entire system unstable on exit. As this is the third one I have written, I must be doing SOMETHING differently. I suppose once I fiond the cause it will all be blindingly obvious, as that is the nature of programming.

Thanks for the help guys, I'll try to return the favor one day.

LyleHaze

hypex
hypex's picture
Offline
Last seen: 3 months 3 weeks ago
Joined: 2011-09-09 16:20
Re: Some newlib dummys questions

Broadblues, I said it's easier because I found by specifying CLib2 as the C lib it all compiles nicely. And by default with Newlib and if you prefer it then you have to add some extra startup and closing code. Of course this is going from library code that was created with CLib2 in mind and when CLib2 was default.

hypex
hypex's picture
Offline
Last seen: 3 months 3 weeks ago
Joined: 2011-09-09 16:20
Re: Some newlib dummys questions

Lyle, FWIW, I also tried to load up Deluxe Music and got the crash. It's hard to see why. OS4 audio.device used to have a bug where it returned a zero locking key and this can cause havoc with some programs. I thought it may be related but the bug may been fixed. I haven't checked lately. :-)

My favorite DM song is Fairy Barque that I heard from a DM demo once many moons ago. Or as I affectionately called it, The Fairly Barbecue. LOL! :-D

whose
whose's picture
Offline
Last seen: 7 years 2 weeks ago
Joined: 2011-08-09 02:25
Re: Some newlib dummys questions

@LyleHaze

I hope you didn´t run into the problem I had back then with "XeroMouse"... take a look at it (it´s on os4depot), source code is included. I had a problem with a reference to a library pointer that was invalid at that point (it´s in the cleanup code).

Coder Insane-Software

www.insane-software.de

salass00
salass00's picture
Offline
Last seen: 6 months 1 week ago
Joined: 2011-02-03 11:27
Re: Some newlib dummys questions

OS4 audio.device used to have a bug where it returned a zero locking key and this can cause havoc with some programs. I thought it may be related but the bug may been fixed. I haven't checked lately. :-)

This was fixed in version 53.3 (11.9.2014) of the AHI based audio.device, which should be the version included with Final Edition.

hypex
hypex's picture
Offline
Last seen: 3 months 3 weeks ago
Joined: 2011-09-09 16:20
Re: Some newlib dummys questions

Thanks salass00 that's good news. That one was an oldie! :-)

Log in or register to post comments