Building shared libraries with Insure++ under AIX
The following Makefile shows how to build a shared library with Insure++
from the files foo.c (a C example) or
Foo.C (a C++ example).
The source file is first compiled into an object (using insure ),
then linked into a shared object (using ins_ld ),
and finally archived into the shared library (using ar ).
The shared library can then be linked with the main program.
If you build C++ shared libs using
/usr/ibmcxx/bin/makeC++SharedLib , it
must be modified. The line
LD=ld
must be changed to
LD=${LD:-ld}
to allow the replacement of ld with ins_ld
when building a library with Insure++.
Here is the Makefile, followed by the source files for these examples.
PRIO = -p 5
#CC=cc
#LD=${LD:-ld}
#CXX=xlC
#LXX=./makeC++SharedLib_r
CC = insure xlc_r
LD = ins_ld
CXX = insure xlC_r
LXX = LD=ins_ld ./makeC++SharedLib_r
all : testfoo testFoo
testfoo: testfoo.c libfoo.a
$(CC) -g -o testfoo testfoo.c -L. -lfoo
libfoo.a: foo.c
$(CC) -c -g foo.c
$(LD) -o foo-shr.o -bM:SRE -bE:foo.exp foo.o -lc
$(AR) ruv libfoo.a foo-shr.o
# For C++ files
testFoo: libFoo.a
$(CXX) -g -o testFoo testfoo.c -L. -lFoo
libFoo.a: Foo.o
$(LXX) $(PRIO) -o Foo-shr.o -bM:SRE -bE:foo.exp Foo.o -lc
$(AR) ruv libFoo.a Foo-shr.o
Foo.o: foo.C
$(CXX) -c -g foo.C -o $@
foo.exp (Export file)
#!
foo
foo.c (C example)
#include <stdio.h>
char *foo(char *s)
{
#ifdef __INSURE__
printf("foo(%s) (INSURE)\n", s);
#else
printf("foo(%s)\n", s);
#endif
return (char *)strdup(s);
}
Foo.C (C++ example)
#include <stdio.h>
#include <string.h>
struct Foo {
Foo(char *p) {
printf("Foo::Foo(%s)\n", p);
}
~Foo() { printf("Foo::~Foo()\n"); }
};
Foo f("hello, there");
extern "C"
char *foo(char *s)
{
#ifdef __INSURE__
printf("foo(%s) (INSURE)\n", s);
#else
printf("foo(%s)\n", s);
#endif
return strdup(s);
}
testfoo.c (Main example program)
#include <stdio.h>
extern char *foo(char *);
extern char *bar(char *);
main(int argc, char *argv[])
{
int i;
for (i = 0; i < argc; i++) {
char *s = foo(argv[i]);
if (i > 2)
free(s);
}
return 0;
}
For more information
call (888) 305-0041, fax (626)305-9048, or
email quality@parasoft.com
|