This discussion is archived
1 Reply Latest reply: Oct 10, 2012 4:12 PM by Steve_Clamage RSS

instlib and shared libraries

887715 Newbie
Currently Being Moderated
I am trying to use -instlib to avoid redundant template instantions, with some shared libraries and programs reusing instantiations already in my main shared library.

Unfortunately, I can't get it to work: I get link errors.

Here is a little test-case:
// File MyTemplate.h
#ifndef MY_TEMPLATE
#define MY_TEMPLATE

template<class T> struct MyTemplate
{
    static T timesTwo(T x)
    {
        return x * 2;
    }
};
#endif
// File f.cpp
#include "MyTemplate.h"
#include <map>

void f()
{
    std::map<int, int> x;

    MyTemplate<int>::timesTwo(5);
}
// File g.cpp
#include "MyTemplate.h"
#include <map>

void g()
{
    std::map<int, int> x;

    MyTemplate<int>::timesTwo(5);
}
// File main.cpp
extern void f();
extern void g();

int main()
{
    f();
    g();
    return 0;
}
# Makefile
FLAGS = -g

all:
        CC -G $(FLAGS) -o libf.so f.cpp
        CC -G $(FLAGS) -instlib=./libf.so -o libg.so g.cpp -L. -lf
        CC $(FLAGS) -o main main.cpp -L. -lg -lf

clean:
        rm -f libf.so libg.so main
This fails with:
CC -g -o main main.cpp -L. -lg -lf
Undefined                       first referenced
 symbol                             in file
std::map<int,int>::~map() ./libg.so
ld: fatal: symbol referencing errors. No output written to main
*** Error code 2
Am I using -instlib incorrectly?

This little test-case links fine if I don't use -g. However, with my much larger libraries, I get link errors with -g, -g0 and -O.

Environment:
~/test$ CC -V
CC: Sun C++ 5.12 SunOS_sparc 2011/11/16
~/test$ uname -a
SunOS sol11 5.11 11.0 sun4v sparc SUNW,SPARC-Enterprise-T5120
Thanks,
Bernard
  • 1. Re: instlib and shared libraries
    Steve_Clamage Pro
    Currently Being Moderated
    You are using -instlib correctly.

    It appears we have a bug in the -instlib implementation. Apparently it does not ignore local symbols, as it should do.

    If you have a service contract with Oracle, please report this problem via your support channel to ensure the bug gets some attention.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points