This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Static libstdc++ and link problems
- From: Frederic RISS <frederic dot riss at st dot com>
- To: libstdc++ at gcc dot gnu dot org
- Date: 17 Jun 2003 09:23:58 +0200
- Subject: Static libstdc++ and link problems
- Organization: STMicroelectronics - DAIS - FlexWare
[I already posted that on gcc-help, but got no answer. I hope not to
be too off-topic on this list]
Hi,
I'm running a Solaris 8 box with gcc 3.2.2 and using GNU binutils. What
I want to do is quite simple : I've a lib written in C++ and which
exposes a C API. I would like the lib to only depend on the libc and not
on libstdc++ ; so I try to link my solib with the static libstdc++.a.
First, is this a totally dumb idea ?
If not, here's a simple example to expose the problem :
----8<------ hello.cc : ---- 8< ----
#include <string>
#include <iostream>
void hello(std::string name)
{
std::cout << "Hello, " << name << " !" << std::endl;
}
extern "C"
void helloC(const char* name)
{
hello(name);
}
----------8<-----------------------
----8<------ main.c : ---- 8< ----
extern void helloC(const char* name);
int main()
{
helloC("Fred");
return 0;
}
----------8<-----------------------
Of course, this works if I do :
$ g++ -fPIC -shared -o libhello.so hello.cc
$ gcc -o hello main.c -lhello -L.
$ ./hello
Hello, Fred !
but if I try to use libstdc++.a, I get this strange error :
$ g++ -fPIC -nostdlib -shared -o libhello.so hello.cc /project/flexware/users/rf23/gcc-3/lib/libstdc++.a -lc
ld: libhello.so: undefined versioned symbol name std::time_get_c@@GLIBCPP_3.2
ld: failed to set dynamic section sizes: Bad value
collect2: ld returned 1 exit status
I found reports of similar failures, but none helped (in fact they often
got no answer). I also tried to use Sun binutils, but it failed as well
(differently, but it didn't work). I tried with a brand new GCC 3.3 and
got the same error.
Any clue ?
Regards,
Fred