Welcome, Guest. Please login or register.

Author Topic: Making a shared library  (Read 2393 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline nyteschaydeTopic starter

  • VIP / Donor - Lifetime Member
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 644
    • Show only replies by nyteschayde
    • http://www.nyteshade.com
Making a shared library
« 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.
Senior MTS Software Engineer with PayPal
Amigas: A1200T 060/603e PPC • A1200T 060 • A4000D 040 • A3000 (x2) • A2000 Vamp/V2 • A1200 (x4) • A1000 (x3) • A600 Vamp/V1 • A500
 

Offline Thomas

Re: Making a shared library
« Reply #1 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

Offline nyteschaydeTopic starter

  • VIP / Donor - Lifetime Member
  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 644
    • Show only replies by nyteschayde
    • http://www.nyteshade.com
Re: Making a shared library
« Reply #2 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. :)
Senior MTS Software Engineer with PayPal
Amigas: A1200T 060/603e PPC • A1200T 060 • A4000D 040 • A3000 (x2) • A2000 Vamp/V2 • A1200 (x4) • A1000 (x3) • A600 Vamp/V1 • A500
 

Offline woof

  • Jr. Member
  • **
  • Join Date: Feb 2003
  • Posts: 94
    • Show only replies by woof
    • http://uae.is.free.fr
Re: Making a shared library
« Reply #3 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
 

Offline mousehouse

Re: Making a shared library
« Reply #4 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/
A3000T
 

Offline itix

  • Hero Member
  • *****
  • Join Date: Oct 2002
  • Posts: 2380
    • Show only replies by itix
Re: Making a shared library
« Reply #5 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.
My Amigas: A500, Mac Mini and PowerBook