Warum erhalte ich selbst mit -ldl für dieses einfache Programm einen "undefinierten Verweis auf" dladdr "?

Ich arbeite durch eineLLVM Tutorial, aber ich habe Probleme beim Kompilieren. Ich habe ein minimales Beispiel geschrieben, das das Problem reproduziert:

#include "llvm/Module.h"
#include "llvm/LLVMContext.h"

int main(int argc, char **argv) {
    llvm::Module *module = new llvm::Module("test", llvm::getGlobalContext());
    return 0;
}

Wenn ich versuche zu kompilieren, erhalte ich eine Reihe von 'undefinierten Referenz'-Fehlern:

clang++ `llvm-config --cxxflags`   -c -o test.o test.cpp
clang++  test.o  `llvm-config --ldflags --libs core` -o test
/usr/lib/llvm-2.9/lib/libLLVMSupport.a(Signals.o): In function `PrintStackTrace(void*)':
(.text+0x6c): undefined reference to `dladdr'
/usr/lib/llvm-2.9/lib/libLLVMSupport.a(Signals.o): In function `PrintStackTrace(void*)':
(.text+0x1f6): undefined reference to `dladdr'
/usr/lib/llvm-2.9/lib/libLLVMSupport.a(Mutex.o): In function `llvm::sys::MutexImpl::MutexImpl(bool)':
(.text+0x53): undefined reference to `pthread_mutexattr_init'
/usr/lib/llvm-2.9/lib/libLLVMSupport.a(Mutex.o): In function `llvm::sys::MutexImpl::MutexImpl(bool)':
(.text+0x64): undefined reference to `pthread_mutexattr_settype'
/usr/lib/llvm-2.9/lib/libLLVMSupport.a(Mutex.o): In function `llvm::sys::MutexImpl::MutexImpl(bool)':
(.text+0x74): undefined reference to `pthread_mutexattr_setpshared'
/usr/lib/llvm-2.9/lib/libLLVMSupport.a(Mutex.o): In function `llvm::sys::MutexImpl::MutexImpl(bool)':
(.text+0x88): undefined reference to `pthread_mutexattr_destroy'
/usr/lib/llvm-2.9/lib/libLLVMSupport.a(Mutex.o): In function `llvm::sys::MutexImpl::tryacquire()':
(.text+0x179): undefined reference to `pthread_mutex_trylock'
/usr/lib/llvm-2.9/lib/libLLVMSupport.a(RWMutex.o): In function `llvm::sys::RWMutexImpl::RWMutexImpl()':
(.text+0x3e): undefined reference to `pthread_rwlock_init'
/usr/lib/llvm-2.9/lib/libLLVMSupport.a(RWMutex.o): In function `llvm::sys::RWMutexImpl::~RWMutexImpl()':
(.text+0x80): undefined reference to `pthread_rwlock_destroy'
/usr/lib/llvm-2.9/lib/libLLVMSupport.a(RWMutex.o): In function `llvm::sys::RWMutexImpl::reader_acquire()':
(.text+0xb9): undefined reference to `pthread_rwlock_rdlock'
/usr/lib/llvm-2.9/lib/libLLVMSupport.a(RWMutex.o): In function `llvm::sys::RWMutexImpl::reader_release()':
(.text+0xe9): undefined reference to `pthread_rwlock_unlock'
/usr/lib/llvm-2.9/lib/libLLVMSupport.a(RWMutex.o): In function `llvm::sys::RWMutexImpl::writer_acquire()':
(.text+0x119): undefined reference to `pthread_rwlock_wrlock'
/usr/lib/llvm-2.9/lib/libLLVMSupport.a(RWMutex.o): In function `llvm::sys::RWMutexImpl::writer_release()':
(.text+0x149): undefined reference to `pthread_rwlock_unlock'
/usr/lib/llvm-2.9/lib/libLLVMSupport.a(Threading.o): In function `llvm::llvm_execute_on_thread(void (*)(void*), void*, unsigned int)':
(.text+0x1cc): undefined reference to `pthread_create'
/usr/lib/llvm-2.9/lib/libLLVMSupport.a(Threading.o): In function `llvm::llvm_execute_on_thread(void (*)(void*), void*, unsigned int)':
(.text+0x208): undefined reference to `pthread_attr_setstacksize'
/usr/lib/llvm-2.9/lib/libLLVMSupport.a(Threading.o): In function `llvm::llvm_execute_on_thread(void (*)(void*), void*, unsigned int)':
(.text+0x228): undefined reference to `pthread_join'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [test] Error 1

Wenn ich die Manpage für dladdr ansehe, muss ich einen Link zu erstellen-ldl. Aber ich mache das schon mitllvm-config:

$ llvm-config --ldflags --libs core
-L/usr/lib/llvm-2.9/lib  -lpthread -lffi -ldl -lm 
-lLLVMCore -lLLVMSupport -L/usr/lib/llvm-2.9/lib

Zusätzlich,-ldl erscheint in der richtigen Reihenfolge (d. h. nach dem.o Datei, die die Symbole erfordert).

Ich bin ratlos für den nächsten Schritt beim Debuggen dieses Problems. Kann mich jemand in die richtige Richtung weisen? Ich verwende LVVM 2.9-7 unter Ubuntu 12.04.

Antworten auf die Frage(2)

Ihre Antwort auf die Frage