wpy
asked on
How to create a dynamic lib with c on HP/unix
How to create a dynamic lib with c on HP/unix.
1. The rule to write the source files?
2. How to create it?
3. How to call function in a dynamic lib?
Example will be thankful!
1. The rule to write the source files?
2. How to create it?
3. How to call function in a dynamic lib?
Example will be thankful!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you don't have the GNU stuff available, basically all you have to do is:
$ cc -Aa -c +z length.c volume.c mass.c
$ ld -b -o libunits.sl length.o volume.o mass.o
the two commands above compile the translation units lenght.c, volume.c
and mass.c. All three .o files are combined into a shared library libunits.sl
I stole this example from:
http://wsspinfo.cern.ch/file/man.html
One of the links of from this page leads to HP/UX specific stuff ...
kind regards,
Jos aka jos@and.nl
ps. I sincerely _hate_ all those different linker options ...
$ cc -Aa -c +z length.c volume.c mass.c
$ ld -b -o libunits.sl length.o volume.o mass.o
the two commands above compile the translation units lenght.c, volume.c
and mass.c. All three .o files are combined into a shared library libunits.sl
I stole this example from:
http://wsspinfo.cern.ch/file/man.html
One of the links of from this page leads to HP/UX specific stuff ...
kind regards,
Jos aka jos@and.nl
ps. I sincerely _hate_ all those different linker options ...
ASKER
Thanks very much!
ASKER
Thanks very much!
Have you any sample of shl_load(3X) and the relative functions on HP/Unix?
Please help!
Have you any sample of shl_load(3X) and the relative functions on HP/Unix?
Please help!
Ok, here goes:
#include <stdio.h>
#include <dl.h>
/* a function pointer type: taking one double arg, returning a double: */
typedef double (*funcp_t)(double);
int main() {
shl_t handle; /* handle to the shared archive */
funcp_t cosine; /* pointer to a function */
/* try to open the math archive */
handle= shl_load("/usr/lib/libm", BIND_IMMEDIATE);
if (!handle) {
perror("can't find lib");
exit(1);
}
/* try to find the 'cos' symbol */
if (shl_findsym(handle, "cos", TYPE_PROCEDURE, &cosine) != 0) {
perror("can't find symbol");
exit(1);
}
/* do something with the 'cos' symbol: */
printf("cosine(1.0)= %f\n", cosine(1.0));
/* and detach the archive again */
shl_unload(handle);
return 0;
}
This is from the top of my head, (and totally untested), by I think you get the
picture ...
kind regards,
Jos aka jos@and.nl
#include <stdio.h>
#include <dl.h>
/* a function pointer type: taking one double arg, returning a double: */
typedef double (*funcp_t)(double);
int main() {
shl_t handle; /* handle to the shared archive */
funcp_t cosine; /* pointer to a function */
/* try to open the math archive */
handle= shl_load("/usr/lib/libm", BIND_IMMEDIATE);
if (!handle) {
perror("can't find lib");
exit(1);
}
/* try to find the 'cos' symbol */
if (shl_findsym(handle, "cos", TYPE_PROCEDURE, &cosine) != 0) {
perror("can't find symbol");
exit(1);
}
/* do something with the 'cos' symbol: */
printf("cosine(1.0)= %f\n", cosine(1.0));
/* and detach the archive again */
shl_unload(handle);
return 0;
}
This is from the top of my head, (and totally untested), by I think you get the
picture ...
kind regards,
Jos aka jos@and.nl
ASKER
Thanks very much! I'll test it.
ASKER