Click Here
home features news forums classifieds faqs links search
6155 members 
Amiga Q&A /  Free for All /  Emulation /  Gaming / (Latest Posts)
Login

Nickname

Password

Lost Password?

Don't have an account yet?
Register now!

Support Amigaworld.net
Your support is needed and is appreciated as Amigaworld.net is primarily dependent upon the support of its users.
Donate

Menu
Main sections
» Home
» Features
» News
» Forums
» Classifieds
» Links
» Downloads
Extras
» OS4 Zone
» IRC Network
» AmigaWorld Radio
» Newsfeed
» Top Members
» Amiga Dealers
Information
» About Us
» FAQs
» Advertise
» Polls
» Terms of Service
» Search

IRC Channel
Server: irc.amigaworld.net
Ports: 1024,5555, 6665-6669
SSL port: 6697
Channel: #Amigaworld
Channel Policy and Guidelines

Who's Online
22 crawler(s) on-line.
 95 guest(s) on-line.
 0 member(s) on-line.



You are an anonymous user.
Register Now!

/  Forum Index
   /  Amiga Development
      /  Compiling/Linking Shared Library
Register To Post

Goto page ( Previous Page 1 | 2 )
PosterThread
Wanderer 
Re: Compiling/Linking Shared Library
Posted on 22-Apr-2013 16:40:53
#21 ]
Cult Member
Joined: 16-Aug-2008
Posts: 654
From: Germany

@itix

What do you mean by "executing constructors"?

I finally was able to compile a library. But while doing that, I found that the z.library can do most of the things I need. So I will probably use the z.library. I assume it will be the same across Amiga platforms. I will cancel my attempt to throw yet another zlib port into the game, as it will cause more trouble than it helps. Instead, I will have to do it the hard way to implrement compress2 by low level functions.


_________________
--
Author of
HD-Rec, Sweeper, Samplemanager, ArTKanoid, Monkeyscript, Toadies, AsteroidsTR, TuiTED, PosTED, TKPlayer, AudioConverter, ScreenCam, PerlinFX, MapEdit, AB3 Includes and many more...
Homepage: http://www.hd-rec.de

 Status: Offline
Profile     Report this post  
wawa 
Re: Compiling/Linking Shared Library
Posted on 22-Apr-2013 16:55:11
#22 ]
Elite Member
Joined: 21-Jan-2008
Posts: 6259
From: Unknown

@Wanderer, itix

i dont know z.library in particular, but i think it makes sense to upgrade a port if/where necessary while keeping the library name as long as it is possible to keep backwards compatible. i think generally such an attempt should be kept in sync on 68k, aros, mos and os4.

i aree there shouldnt be different concurring libs under the same name, leading to confusions. but also i would hate to have different dynamic lib of similar functionality for each case with a slightly different naming. we have had this debate with ixemul. therefore as a rule of the thumb should be that the libraries in question should be open and worked on together.

 Status: Offline
Profile     Report this post  
Crumb 
Re: Compiling/Linking Shared Library
Posted on 22-Apr-2013 17:08:51
#23 ]
Elite Member
Joined: 12-Mar-2003
Posts: 2209
From: Zaragoza (Aragonian State)

@Wanderer
An updated port this wouldn't be bad as long as it's API compatible:
http://aminet.net/package/util/libs/zlib-library

If you wish to add new functions you can add them to existing ones so you keep the library compatible.

If you need a more modern API perhaps taking a look at z.library from MorphOS could be helpful so you implement exactly the same API.

_________________
The only spanish amiga news web page/club: CUAZ

 Status: Offline
Profile     Report this post  
wawa 
Re: Compiling/Linking Shared Library
Posted on 22-Apr-2013 17:13:06
#24 ]
Elite Member
Joined: 21-Jan-2008
Posts: 6259
From: Unknown

@Crumb

but in case morphos z.lib has a different api than the 68k one and not just extended, then the new library should be called something else, not to mention it would be better for mos having a different name as well, but then its obviously too late.
i hope its only an extended one though.

 Status: Offline
Profile     Report this post  
OlafS25 
Re: Compiling/Linking Shared Library
Posted on 22-Apr-2013 17:16:53
#25 ]
Elite Member
Joined: 12-May-2010
Posts: 6573
From: Unknown

@Crumb

I got the source of zlib from achim stegemann so when there is interest I could upload it on aminet

 Status: Offline
Profile     Report this post  
x303 
Re: Compiling/Linking Shared Library
Posted on 22-Apr-2013 17:46:49
#26 ]
Regular Member
Joined: 19-Jan-2005
Posts: 181
From: Amsterdam

@OlafS25

Quote:
I got the source of zlib from achim stegemann so when there is interest I could upload it on aminet

The source is already included in the package, so there's no need to upload it.

 Status: Offline
Profile     Report this post  
itix 
Re: Compiling/Linking Shared Library
Posted on 23-Apr-2013 11:14:46
#27 ]
Elite Member
Joined: 22-Dec-2004
Posts: 3398
From: Freedom world

@Wanderer

Quote:

What do you mean by "executing constructors"?


Startup code required to initialize (and also finally cleanup) clib services tha tneed to be initialized properly before using and cleaned up when you leave (library is closed).

Unfortunately 68k libnix never complains if constructors are not executed so you never know if it is needed or not. Generally I/O need to be initialized via constructors before using. It can work without, though.

_________________
Amiga Developer
Amiga 500, Efika, Mac Mini and PowerBook

 Status: Offline
Profile     Report this post  
itix 
Re: Compiling/Linking Shared Library
Posted on 23-Apr-2013 11:25:23
#28 ]
Elite Member
Joined: 22-Dec-2004
Posts: 3398
From: Freedom world

@wawa

Yes unfortunately MorphOS z.library was developed without being aware there already was 68k z.library developed in 1998. When this name conflict was found it was too late. I recall rationale back then was that z.library seemed abandonded and Stegemann's zlib.library was more popular.

MorphOS z.library uses SysV ABI and 68k z.library uses M68K ABI.

_________________
Amiga Developer
Amiga 500, Efika, Mac Mini and PowerBook

 Status: Offline
Profile     Report this post  
wawa 
Re: Compiling/Linking Shared Library
Posted on 23-Apr-2013 11:36:35
#29 ]
Elite Member
Joined: 21-Jan-2008
Posts: 6259
From: Unknown

@itix

thats unfortunate. however a immediate incovinience is actually only on mos side if one was to run any 68k application that depends on z.lib. in turn it will never hurt 68k itself as you dont run mos apps on it, and will likely only make porting harder. it could be a little hassle for aros as to whom stay compatible, even though genuine amiga/68k is likely all time the preference. nevertheless there was some issue of whatever kind i dont remember with the outcome that there is z_au.library on aros instead of z.library i guess.

 Status: Offline
Profile     Report this post  
broadblues 
Re: Compiling/Linking Shared Library
Posted on 23-Apr-2013 11:48:10
#30 ]
Amiga Developer Team
Joined: 20-Jul-2004
Posts: 4456
From: Portsmouth England

@wawa

I wander which version the AmigaOS4 z.library is compatable with ?

_________________
BroadBlues On Blues BroadBlues On Amiga Walker Broad

 Status: Offline
Profile     Report this post  
broadblues 
Re: Compiling/Linking Shared Library
Posted on 23-Apr-2013 11:59:52
#31 ]
Amiga Developer Team
Joined: 20-Jul-2004
Posts: 4456
From: Portsmouth England

@itix

Quote:

Startup code required to initialize (and also finally cleanup) clib services tha tneed to be initialized properly before using and cleaned up when you leave (library is closed).

Unfortunately 68k libnix never complains if constructors are not executed so you never know if it is needed or not. Generally I/O need to be initialized via constructors before using. It can work without, though.


@Wanderer
Found the libnix init code for Aweb aweblibs it's scattered across a few files but it does all the constructor stuff you may aor may need for this;

The code below will call all the constructors and destructors required for libnix and allow just about any libnix code to run in an amiga library.

init is called during library init, exit during expunge.

GCC builds the constructor / destructor lists during linkng.







##module.h

#define INIT_SUCCESS 1
#define INIT_FAIL 0

#define ASCENDING 1
#define DESCENDING 0


struct FunctionListItem
{
void (*fli_Func)(void);
int fli_Pri;
};

struct FunctionList
{
int fl_Size;
struct FunctionListItem fl_Funcs[0];
};

extern struct DosLibrary *__DOSBase;
extern struct Library *__UtilityBase;
extern struct Library *__MathIeeeDoubTransBase;
extern struct Library *__MathIeeeDoubBasBase;
extern struct Library *__MathIeeeSingBasBase;
extern struct WBStartup *_WBenchMsg;

extern struct FunctionList __INIT_LIST__ , __EXIT_LIST__;


extern int AwebModuleInit(void);
extern void AwebModuleExit(void);

extern int OpenModuleLibraries(void);
extern void CloseModuleLibraries(void);
extern void CallFunctionList(struct FunctionList *funcs, int direction);


----
#module_init.c

#include <stdio.h>

#include "module.h"


int __nocommandline = 0;

struct FunctionList __INIT_LIST__ = {0};

int AwebModuleInit(void)
{
if(!OpenModuleLibraries())
{

CloseModuleLibraries();
return INIT_FAIL;

}

CallFunctionList(&__INIT_LIST__, ASCENDING);

return INIT_SUCCESS;
}
---
##module_exit.c

#include <stdio.h>
#include <exec/types.h>

#include "module.h"

struct FunctionList __EXIT_LIST__ = {0};

void AwebModuleExit(void)
{

CallFunctionList(&__EXIT_LIST__, DESCENDING);
CloseModuleLibraries();

}




void exit()
{

}

----
#module_calll.c


#include "module.h"

/* CallFunctionList() calls all the functions in Ascending or */
/* Descending order of priority */
/* This function uses a similar algorithm to the standard libnix startup code */
/* to sort through the priorities but re-implemented in C */


void CallFunctionList( struct FunctionList *funcs, int direction)
{
unsigned char current_pri;
unsigned char running_pri;
int not_done = 0;

current_pri = (direction == ASCENDING ? 0 : 255 );
running_pri = (direction == ASCENDING ? 255 : 0 );

do
{
int i;
not_done = 0;
for(i=0;i < funcs->fl_Size / 2; i++)
{

/* execute function if at relavent priority */

if (funcs->fl_Funcs[i].fli_Pri == current_pri)
{

funcs->fl_Funcs[i].fli_Func();

}

if (direction == ASCENDING)
{

if (
(funcs->fl_Funcs[i].fli_Pri < running_pri) &&
(funcs->fl_Funcs[i].fli_Pri > current_pri) )
{
running_pri = funcs->fl_Funcs[i].fli_Pri;
not_done |= 1;
}

}
else
{

if (
(funcs->fl_Funcs[i].fli_Pri > running_pri) &&
(funcs->fl_Funcs[i].fli_Pri < current_pri) )
{
running_pri = funcs->fl_Funcs[i].fli_Pri;
not_done |= 1;
}

}

}

current_pri = running_pri;
running_pri = (direction == ASCENDING ? 255 : 0 );

} while (not_done);


}

----
##module_libraries

#include <exec/types.h>
#include <exec/execbase.h>
#include <dos/dosextens.h>
#include <proto/exec.h>

#include "module.h"


struct ExecBase *SysBase = NULL;
struct DosLibrary *__DOSBase = NULL;
struct Library *__UtilityBase = NULL;
struct Library *__MathIeeeSingBasBase = NULL;
struct Library *__MathIeeeDoubTransBase = NULL;
struct Library *__MathIeeeDoubBasBase = NULL;
struct WBStartup *_WBenchMsg = NULL;

int OpenModuleLibraries(void)
{

SysBase = *(struct ExecBase **)4;

if(
(__DOSBase = (struct DosLibrary *)OpenLibrary("dos.library",39L)) &&
(__UtilityBase = OpenLibrary("utility.library",37L)) &&
(__MathIeeeSingBasBase = OpenLibrary("mathieeesingbas.library",33L)) &&
(__MathIeeeDoubBasBase = OpenLibrary("mathieeedoubbas.library",33L)) &&
(__MathIeeeDoubTransBase = OpenLibrary("mathieeedoubtrans.library",33L))
) return INIT_SUCCESS;

CloseModuleLibraries();

return INIT_FAIL;

}

void CloseModuleLibraries()
{

if(__MathIeeeDoubTransBase)CloseLibrary(__MathIeeeDoubTransBase);
if(__MathIeeeDoubBasBase)CloseLibrary(__MathIeeeDoubBasBase);
if(__MathIeeeSingBasBase)CloseLibrary(__MathIeeeSingBasBase);
if(__UtilityBase)CloseLibrary(__UtilityBase);
if(__DOSBase)CloseLibrary((struct Library *)__DOSBase);

}



Last edited by broadblues on 23-Apr-2013 at 11:28 PM.

_________________
BroadBlues On Blues BroadBlues On Amiga Walker Broad

 Status: Offline
Profile     Report this post  
Wanderer 
Re: Compiling/Linking Shared Library
Posted on 23-Apr-2013 13:03:56
#32 ]
Cult Member
Joined: 16-Aug-2008
Posts: 654
From: Germany

@broadblues

I dont understand what exactly is the "contructor". In the source are some parts missing, because the browser thinks they are HTML tags.

Anyway, do you mean by contructors to open some libraries in the init code, or is it this:

CallFunctionList(&__INIT_LIST__, ASCENDING);
CallFunctionList(&__EXIT_LIST__, DESCENDING);

Do I understand correctly, the __INIT_LIST__ is a list of function pointers that are defined once I use "-libnix" ? And I should call them using this fancy algorithm, and there is no simple call (like init_libnix() ) for this?

2. I think the OS4 z.library uses the 68K API, since its readme says it is based on the 68K from 1998.

So, this means now that I have migrated my software from zlib.library to z.library, it won't run on MOS anymore? Crap! Looks like I need to compile my own version finally.

Last edited by Wanderer on 23-Apr-2013 at 01:14 PM.
Last edited by Wanderer on 23-Apr-2013 at 01:05 PM.

_________________
--
Author of
HD-Rec, Sweeper, Samplemanager, ArTKanoid, Monkeyscript, Toadies, AsteroidsTR, TuiTED, PosTED, TKPlayer, AudioConverter, ScreenCam, PerlinFX, MapEdit, AB3 Includes and many more...
Homepage: http://www.hd-rec.de

 Status: Offline
Profile     Report this post  
wawa 
Re: Compiling/Linking Shared Library
Posted on 23-Apr-2013 13:49:53
#33 ]
Elite Member
Joined: 21-Jan-2008
Posts: 6259
From: Unknown

@Wanderer

in this case why not to link it static. it will run everywhere without conflicts and you can skip all that shared lib compiling trouble. shared libs are of course more elegant and useful when used by more programs, but when there is no consens its only add to trouble building just another library for the same task.

Last edited by wawa on 23-Apr-2013 at 01:50 PM.

 Status: Offline
Profile     Report this post  
Wanderer 
Re: Compiling/Linking Shared Library
Posted on 23-Apr-2013 14:06:06
#34 ]
Cult Member
Joined: 16-Aug-2008
Posts: 654
From: Germany

@wawa

There are actually 2 reasons for a dynamic library:

1. I need it in Amiblitz, and here we can only use shared libraries

2. CPU hungry stuff is better put to libraries, that can run native on the host system, since Amiblitz is 68K

_________________
--
Author of
HD-Rec, Sweeper, Samplemanager, ArTKanoid, Monkeyscript, Toadies, AsteroidsTR, TuiTED, PosTED, TKPlayer, AudioConverter, ScreenCam, PerlinFX, MapEdit, AB3 Includes and many more...
Homepage: http://www.hd-rec.de

 Status: Offline
Profile     Report this post  
broadblues 
Re: Compiling/Linking Shared Library
Posted on 23-Apr-2013 23:17:17
#35 ]
Amiga Developer Team
Joined: 20-Jul-2004
Posts: 4456
From: Portsmouth England

@Wanderer

Quote:

I dont understand what exactly is the "contructor". In the source are some parts missing, because the browser thinks they are HTML tags.


Darn forgot about that, will fix them in a sec.

As to the constructor, If you study the libnix source you'll see functions declared so that they are added to the lists you quoted below. For each module compiled in (which will depend on which C library function you use) the constructor / destructor functions are added to the lists.

They are then called by the normal libnix startup code and initialise things like stdio.

Quote:


Anyway, do you mean by contructors to open some libraries in the init code, or is it this:

CallFunctionList(&__INIT_LIST__, ASCENDING);
CallFunctionList(&__EXIT_LIST__, DESCENDING);

Do I understand correctly, the __INIT_LIST__ is a list of function pointers that are defined once I use "-libnix" ? And I should call them using this fancy algorithm, and there is no simple call (like init_libnix() ) for this?


That's rough;y it yes. There is no init function unfortunatly, unlike clib2 for instance where such a function does exist, so with libnix you mst do it by hand.

Quote:

2. I think the OS4 z.library uses the 68K API, since its readme says it is based on the 68K from 1998.

So, this means now that I have migrated my software from zlib.library to z.library, it won't run on MOS anymore? Crap! Looks like I need to compile my own version finally.


Perhaps you can check for OS and use the most appropriate exsiting library?


_________________
BroadBlues On Blues BroadBlues On Amiga Walker Broad

 Status: Offline
Profile     Report this post  
salass00 
Re: Compiling/Linking Shared Library
Posted on 24-Apr-2013 11:26:25
#36 ]
Elite Member
Joined: 31-Oct-2003
Posts: 2707
From: Finland

@Wanderer

z.library for AmigaOS >= 4.0
http://aminet.net/package/util/libs/z_library

Has m68k style jumptable as well as AmigaOS 4.x style interface.

AmigaOS 3.x and AROS versions are included with diskimage.device releases:
http://aminet.net/disk/misc/diskimage.m68k-aos.tar.bz2
http://aminet.net/package/disk/misc/diskimage.i386-aros
http://aminet.net/disk/misc/diskimage.ppc-aros.tar.bz2

Source code for this version is available here:
http://sf.net/projects/diskimagedevice

 Status: Offline
Profile     Report this post  
Wanderer 
Re: Compiling/Linking Shared Library
Posted on 24-Aug-2013 15:45:33
#37 ]
Cult Member
Joined: 16-Aug-2008
Posts: 654
From: Germany

@broadblues

Big thanks! This actually made my library project work. Without this hint I wouldnt make it.

_________________
--
Author of
HD-Rec, Sweeper, Samplemanager, ArTKanoid, Monkeyscript, Toadies, AsteroidsTR, TuiTED, PosTED, TKPlayer, AudioConverter, ScreenCam, PerlinFX, MapEdit, AB3 Includes and many more...
Homepage: http://www.hd-rec.de

 Status: Offline
Profile     Report this post  
Goto page ( Previous Page 1 | 2 )

[ home ][ about us ][ privacy ] [ forums ][ classifieds ] [ links ][ news archive ] [ link to us ][ user account ]
Copyright (C) 2000 - 2019 Amigaworld.net.
Amigaworld.net was originally founded by David Doyle