1 Reply Latest reply on Oct 10, 2012 11:12 PM by Steve.Clamage-Oracle

    instlib and shared libraries

      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;
      // 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 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
              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.

      ~/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
          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.
          1 person found this helpful