Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Building shared libraries with Insure++ under AIX

LegacyForum Posts: 1,664 ✭✭
edited December 2016 in Insure++
Building shared libraries with Insure++
Building shared libraries with Insure++ under AIX:

The Makefile below has been modified to build a shared library with Insure++. The foo.c and Foo.C source files are first compiled into an object (using insure), then linked into a shared object , and finally archived into the shared library. The shared library can then be linked with the main program.

If you build C++ shared libs using /usr/ibmcxx/bin/makeC++SharedLib. Copy the makeC++SharedLib file, give the file you copied a name you are comfortable with, for example, makeC++SharedLib_ins. Now you have two files the makeC++SharedLib_ins file will work exclusively with Insure, and the makeC++SharedLib file will work without Insure. Modify the new makeC++SharedLib_ins file, changing the LD line

LD=ins_ld. .

After modifying the makeC++SharedLib_ins file, you need to change a few lines in your Makefile.

CC = insure
LD= ins_ld
CXX = insure xlC
LXX =/usr/ibmcxx/bin/makeC++SharedLib_ins

CC = insure
LD = ins_ld
CXX = insure xlC
PRIO = -p 5

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.C
$(CXX) -c -g Foo.C
$(LXX) $(PRIO) -o Foo-shr.o -bM:SRE -bE:foo.exp Foo.o -lc
$(AR) ruv libFoo.a Foo-shr.o


foo.exp (Export file)

foo.c (C example)
/* foo.c */

#include <stdio.h>
char *foo(char *s)
#ifdef __INSIGHT__
printf("foo(%s) (INSIGHT)\n", s);
printf("foo(%s)\n", s);
return strdup(s);

Foo.C (C++ example)
/* Foo.C */

#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 __INSIGHT__
printf("foo(%s) (INSIGHT)\n", s);
printf("foo(%s)\n", s);
return strdup(s);

testfoo.c (Main example program)
/* testfoo.c */
#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)
return 0;