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

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

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

// File g.cpp
#include "MyTemplate.h"
#include <map>

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

// File main.cpp
extern void f();
extern void g();

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

        CC -G $(FLAGS) -o f.cpp
        CC -G $(FLAGS) -instlib=./ -o g.cpp -L. -lf
        CC $(FLAGS) -o main main.cpp -L. -lg -lf

        rm -f main
This fails with:
CC -g -o main main.cpp -L. -lg -lf
Undefined                       first referenced
 symbol                             in file
std::map<int,int>::~map() ./
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.

~/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
  • 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.


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