Login
Username:

Password:

Remember me



Lost Password?

Register now!
Sections
Who's Online
55 user(s) are online (45 user(s) are browsing Forums)

Members: 0
Guests: 55

more...
Support us!
Recent OS4 Files
OS4Depot.net
Report message:*
 

library auto init code

Subject: library auto init code
by billyfish on 2016/12/23 13:08:42

Hi all

I'm trying to write a library that is able to be opened automatically by other programs using the -lauto flag when compiling them and I'm running into problems. It must be missing something out, but I'm stuck!

I took the example at http://wiki.amigaos.net/wiki/How_to_create_an_AmigaOS_4_library and built the subsequent sample.library. I noticed that idltool created two auto-init source files, autoinit_sample_base.c and autoinit_sample_main.c which weren't being referenced in the generated makefile. So I added them to the makefile sources and built the library.

I then used the following test program based upon the test program in the article. If you run it without any command line args, it will explicitly open the sample library and its interface. If you specify a command line arg, I thought that it should use the auto-init code. I compiled the program using

gcc test.c -o test -lauto -gstabs -I../include

However if I try to run it using the auto-init code, ISample is never initialised. My question is what am I doing wrong?

An archive containing all of the files is at https://www.dropbox.com/s/sy130r5aorl26op/sample.lha?dl=0 and the code for test.c is below

#include <proto/exec.h>
#include <proto/sample.h>
 
#include <stdio.h>
 
int main(int argcchar *argv[])
{
  
myInt val1val2res;
 
  
struct Library *SampleBase NULL;
  
struct SampleIFace *ISample NULL;
 
  
/*
    If no command line args are apssed in, explicitly open the library.
    If any command line args are passed in, then try to use auto init.
  */
  
if (argc == 1)
    {
      
SampleBase = (struct Library *)IExec->OpenLibrary("sample.library"0);
      if(!
SampleBase)
        {
          return -
1;
        }
    
       
ISample = (struct SampleIFace *)IExec->GetInterface(SampleBase"main"1NULL);
       if(!
ISample)
        {
          
IExec->CloseLibrary(SampleBase);
          return -
2;
        }
    }
 
  
val1 123;
  
val2 321;
 
  if (
ISample)
    {
      
res ISample->Addition(val1val2);
      
printf("%ld + %ld = %ldn"val1val2res);
    }
  else
    {
      
printf ("Error: ISample has not been openedn");
    }
 
  if (
argc == 1)
    {
      
IExec->DropInterface((struct Interface *)ISample);
      
IExec->CloseLibrary(SampleBase);
    }
 
  return 
0;
}



cheers

Billy

Powered by XOOPS 2.0 © 2001-2016 The XOOPS Project