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 argc, char *argv[])
{
myInt val1, val2, res;
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", 1, NULL);
if(!ISample)
{
IExec->CloseLibrary(SampleBase);
return -2;
}
}
val1 = 123;
val2 = 321;
if (ISample)
{
res = ISample->Addition(val1, val2);
printf("%ld + %ld = %ld\n", val1, val2, res);
}
else
{
printf ("Error: ISample has not been opened\n");
}
if (argc == 1)
{
IExec->DropInterface((struct Interface *)ISample);
IExec->CloseLibrary(SampleBase);
}
return 0;
}
cheers
Billy