This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
dlopen ? is it possible to use with stdc++ or a gcc bug ?
- To: gcc-bugs at gcc dot gnu dot org
- Subject: dlopen ? is it possible to use with stdc++ or a gcc bug ?
- From: Levente Farkas <lfarkas at mindmaker dot hu>
- Date: Tue, 17 Oct 2000 17:01:45 +0200
- Cc: drepper at cygnus dot com
- Organization: Mindmaker Ltd.
- Reply-To: lfarkas at mindmaker dot hu
hi,
I'm try to use a simple shared library:
---------------------------
#include <iostream>
void test1()
{
cout << "test1";
}
---------------------------
compile it with :
g++ -c -fPIC -fhonor-std test.cpp -o test.o
create a shared lib with:
export LD_LIBRARY_PATH=/home/lfarkas
g++ test1.o -L/home/lfarkas/ -shared -Wl,-soname,libtest.so.1 -o
/home/lfarkas/libtest.so.1.0
than compile the following test:
---------------------------
#include <stdio.h>
#include <dlfcn.h>
int main(int /*argc*/, char** /*args*/)
{
void* handle;
handle = dlopen("libtest.so", RTLD_LAZY);
if (!handle)
{
fputs(dlerror(), stderr);
return 1;
}
fputs("betoltve", stdout);
typedef void (*type)();
type func = (type)dlsym(handle, "test1");
(*func)();
dlclose(handle);
return 0;
}
---------------------------
g++ -c -fPIC -fhonor-std test.cpp -o test.o
g++ -o a.out test.o -L/home/lfarkas -ldl
and then try to run
./a.out
but the result always (ie on rh 6.2 with my gcc on rh 7.0 with default gcc)
Segmentation fault (core dumped)
not even print any error messages by the dlerror, just simple core dump.
the strange thing if I change the test lib not to use the stdc++ library
(replace iostream/cout with stdio/printf and g++ with gcc) everything
works fine. another strange thing that I can use this test lib if I link
it together with the executable (-ltest) and don't try to load it on
runtime.
anybody has any tip? any tipp would be very useful.
thank you for your help in advance.
yours.
-- Levente http://petition.eurolinux.org/index_html
"The only thing worse than not knowing the truth is
ruining the bliss of ignorance."