title: Why am I getting "undefined reference to `dladdr'" even with -ldl for this simple program?
body: <p>I'm working through an <a href="http://llvm.org/releases/2.6/docs/tutorial/JITTutorial1.html">LLVM Tutorial</a>, but I'm having trouble compiling. I've written a minimal example that reproduces the issue:</p>
  
  <pre><code>#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;
  }
  </code></pre>
  
  <p>When I try to compile, I get a bunch of 'undefined reference' erros:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>If I view the manpage for dladdr, it says that I need to link with <code>-ldl</code>. But I'm already doing that with <code>llvm-config</code>:</p>
  
  <pre><code>$ 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
  </code></pre>
  
  <p>Additionally, <code>-ldl</code> appears in the correct order (i.e., after the <code>.o</code> file that requires the symbols).</p>
  
  <p>I'm at a loss for the next step in debugging this issue. Can anyone point me in the right direction? I'm running LVVM 2.9-7 on Ubuntu 12.04.</p>