Bug#591405: gcc-4.4/g++-4.4: link failure with -Wl, -no-add-needed: "invalid DSO for symbol `pthread_cancel@@GLIBC_2.0' definition"
Smaller testcase:
---- 8< Makefile ----
# $ make
# g++ -Wl,-no-add-needed -shared -o lpthread.so -lpthread
# g++ -Wl,-no-add-needed -o deb591405 deb591405.cpp lpthread.so
# /usr/bin/ld: ,: invalid DSO for symbol `pthread_cancel@@GLIBC_2.0' definition
# /lib/libpthread.so.0: could not read symbols: Bad value
CXX := g++
CXXLD := $(CXX) -Wl,-no-add-needed
#CXXLD := $(CXX)
deb591405: deb591405.cpp lpthread.so
$(CXXLD) -o $@ $+
lpthread.so:
$(CXXLD) -shared -o $@ -lpthread
---- 8< deb591405.cpp -----
/* c++-progs -> library -> pthread
*
* 1. library links to pthread explicitely
* 2. c++-prog does not link to pthread
*
* 3. libstdc++ weakly pulls pthread_cancel, which confuses linker when
* building with -Wl,no-add-needed
*
* See http://bugs.debian.org/591405
*/
#include <string>
#include <iostream>
using namespace std;
int main()
{
string msg = "I hope Debian bug #591405 has been fixed!\n";
cout << msg;
return 0;
}
Reply to: