Amiga.org

Amiga computer related discussion => Amiga Software Issues and Discussion => Topic started by: nyteschayde on October 21, 2011, 06:57:47 AM

Title: Making a shared library
Post by: nyteschayde on October 21, 2011, 06:57:47 AM
So I've put on my Amiga dev cap again and I am trying to figure out if it's possible to create a shared library of functions that I'll reuse using only C. As far as my compiler options go, I currently have Storm C V3.0 (from the ADCD_2.1 CD) and SAS C/6.50.

If I wanted to create a shared library called test.library that exposed a single void tb_hello() function that printed "Hello Amiga" to stdout using something like printf() or puts() what do I have to do?

I expect the usage would be something like:

#include
#include
#include "libs/test.h"

int main(int argc, char **argv) {
  struct Library *TestBase = (struct Library*)OpenLibrary("test.library",0);
  if (TestBase) {
    tb_hello();
    CloseLibrary(TestBase);
  }
  return 0;
}

If I am totally out of my league with this or I should just be using a link library instead, please let me know. My C is rusty and my Amiga C is even rustier.
Title: Re: Making a shared library
Post by: Thomas on October 21, 2011, 07:49:11 AM
Quote from: nyteschayde;664315
If I wanted to create a shared library called test.library that exposed a single void tb_hello() function that printed "Hello Amiga" to stdout using something like printf() or puts() what do I have to do?


You can't do that, at least not as a beginner. It is very difficult to use ANSI C functions in a shared library because the library does not initialize the C runtime environment. And even if it did it would do it in the process of ramlib and not in that of your program.

You can however use every function of AmigaOS in a shared library, for example dos.library/Printf or PutStr.

There is an example library in 100% C on Aminet: http://aminet.net/package/dev/c/CLib37x
Title: Re: Making a shared library
Post by: nyteschayde on October 21, 2011, 07:57:05 AM
PERFECT! Thanks. I'll look this over. I simply chose ANSI functions because they seemed the simplest to type up in my request. Iterating over an exec list would use more space. :)
Title: Re: Making a shared library
Post by: woof on October 21, 2011, 02:59:30 PM
hello

Have a look to aminet/Wazp3D.lha/Wazp3D_lib.c = standard library header
just need to change that part

#define NAMETXT   "Warp3D"
#define VERSION   4
#define REVISION  2
#define DATETXT    "25.09.2006"
#define VERSTXT    "4.2"

aminet/Wazp3D.lha/Wazp3D_functions_glue.h = how to convert a function with parameters in registers to a classic C function + the library jump table

Alain
Title: Re: Making a shared library
Post by: mousehouse on October 21, 2011, 05:53:56 PM
Off topic, but the patches for SAS/C 6.50 -> 6.58 and the addon's to produce PPC code are available as a free download here : http://www.warped.com/amiga/
Title: Re: Making a shared library
Post by: itix on October 21, 2011, 06:39:32 PM
I never owned SAS/C compiler but doesnt it have a switch to create shared libraries very easily? If I am not mistaken SAS/C allowed using ANSI/C functions from shared library easily.