Bug on gcc with dlopen()

Lionel Champalaune Lionel.Champalaune@sophia.inria.fr
Thu Aug 1 00:34:00 GMT 2002


Originator: Lionel Champalaune

Organization: INRIA Sophia Antipolis

Synopsis: problem on opening a shared library

Severity: non-critical

Priority: medium

Category: C++

Class: wrong-code

Release: GCC 3.1.1

Environment: i686-pc-linux

Description:
An error message appear when a shared library is opened.
    > Error: ./libTestlib.so: undefined symbol:
_ZNSt19basic_ostringstreamIcSt11char_traitsIcESaIcEEC1ESt13_Ios_Openmode 
This problem didn't appear with the 3.1 version.
Libtool is used, and it's in the generated compilation that the bug
appears.
This problem doesn't appear when the -g option to gcc is given.
By using g++ instead of gcc, the problem disappear. gcc is used by
libtool in a looklike utilization.

How-To-Repeat:
run the file Command:
        >./Commandgcc

Fix:
Used g++ instead pf gcc in the second line:
      	>./Commandg++
-------------- next part --------------

#include <string>
#include <sstream>

void f()
{
	std::ostringstream ost;
	ost << "toto";
	const std::string s = ost.str();
}


-------------- next part --------------
#include <dlfcn.h>
#include <iostream>

int
main()
{
    void *handle = dlopen ("./libTestlib.so", RTLD_NOW);
    char *error;
    if ((error = dlerror())!=0) {
      std::cerr << "      Error: " << error << std::endl;
      return 1;
    }
}
-------------- next part --------------
g++ -c -o Testlib.lo Testlib.C 
g++ -shared Testlib.lo -Wl,-soname -Wl,libTestlib.so -o libTestlib.so
g++ Testmain.C -ldl
./a.out
-------------- next part --------------
g++ -c -o Testlib.lo Testlib.C 
gcc -shared Testlib.lo -Wl,-soname -Wl,libTestlib.so -o libTestlib.so
g++ Testmain.C -ldl
./a.out


More information about the Gcc-bugs mailing list