Can't build: undefined reference to `dladdr'
Opened this issue · 8 comments
Hello,
I'm trying to build the project but, unfortunately, I receive an error while linking.
Before to start the build process I setup the path to the LLVM installation and the following gcc/g++ variables (the ones I used to build LLVM):
export CC=/usr/bin/gcc-4.8
export CXX=/usr/bin/g++-4.8
I modified also the `lib/CmakeLists.txt" file to solve a problem with the pthread compilation:
@@ -1,3 +1,7 @@
+set(THREADS_PREFER_PTHREAD_FLAG ON)
+find_package(Threads REQUIRED)
+
+
set(SOURCES
ValueUtils.cpp
ValueProfiling.cpp
@@ -44,7 +48,7 @@ add_library(LLVMProfiling-static STATIC
${SOURCES}
)
target_link_libraries(LLVMProfiling-static
- ${LLVM_LIBRARY}
+ ${LLVM_LIBRARY} Threads::Threads tinfo
)
set_target_properties(LLVMProfiling-static
PROPERTIES
@@ -54,7 +58,7 @@ add_library(LLVMProfiling-shared SHARED
${SOURCES}
)
target_link_libraries(LLVMProfiling-shared
- ${LLVM_LIBRARY}
+ ${LLVM_LIBRARY} Threads::Threads tinfo
)
set_target_properties(LLVMProfiling-shared
PROPERTIES
The results of the cmake
command is:
-- The C compiler identification is GNU 4.8.5
-- The CXX compiler identification is GNU 4.8.5
-- Check for working C compiler: /usr/bin/gcc-4.8
-- Check for working C compiler: /usr/bin/gcc-4.8 -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/g++-4.8
-- Check for working CXX compiler: /usr/bin/g++-4.8 -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found LLVM Version 3.5.2svn
-- Could NOT find GTest (missinundefined reference to `dladdr'g: GTEST_INCLUDE_DIR)
-- Add /usr/local/lib/pkgconfig to $PKG_CONFIG_PATH environment variable to let pkg-config find llvm-prof.pc
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Looking for pthread_create
-- Looking for pthread_create - not found
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Found Threads: TRUE
-- Configuring done
-- Generating done
-- Build files have been written to: /local_disk/cornagli/llvm-prof/llvm-prof/build
Now, when the result of the make
command is:
Scanning dependencies of target llvm-prof
[ 75%] Building CXX object src/CMakeFiles/llvm-prof.dir/llvm-prof.cpp.o
[ 76%] Building CXX object src/CMakeFiles/llvm-prof.dir/printer.cpp.o
[ 78%] Building CXX object src/CMakeFiles/llvm-prof.dir/passes.cpp.o
[ 80%] Linking CXX executable llvm-prof
/local_disk/cornagli/llvmTracer/llvm3.5Auto/lib/libLLVMSupport.a(Signals.cpp.o): In function `llvm::sys::PrintStackTrace(_IO_FILE*)':
Signals.cpp:(.text._ZN4llvm3sys15PrintStackTraceEP8_IO_FILE+0x5c): undefined reference to `dladdr'
Signals.cpp:(.text._ZN4llvm3sys15PrintStackTraceEP8_IO_FILE+0xe8): undefined reference to `dladdr'
../lib/libLLVMProfiling.so: undefined reference to `llvm::Statistic::RegisterStatistic()'
../lib/libLLVMProfiling.so: undefined reference to `llvm::LoopInfo::ID'
../lib/libLLVMProfiling.so: undefined reference to `llvm::LoopInfoBase<llvm::BasicBlock, llvm::Loop>::getLoopFor(llvm::BasicBlock const*) const'
../lib/libLLVMProfiling.so: undefined reference to `llvm::LoopInfoBase<llvm::BasicBlock, llvm::Loop>::isLoopHeader(llvm::BasicBlock*) const'
../lib/libLLVMProfiling.so: undefined reference to `llvm::LoopBase<llvm::BasicBlock, llvm::Loop>::contains(llvm::BasicBlock const*) const'
../lib/libLLVMProfiling.so: undefined reference to `llvm::SplitCriticalEdge(llvm::TerminatorInst*, unsigned int, llvm::Pass*, bool, bool, bool)'
../lib/libLLVMProfiling.so: undefined reference to `llvm::LoopBase<llvm::BasicBlock, llvm::Loop>::getLoopLatch() const'
../lib/libLLVMProfiling.so: undefined reference to `llvm::LoopBase<llvm::BasicBlock, llvm::Loop>::getExitEdges(llvm::SmallVectorImpl<std::pair<llvm::BasicBlock const*, llvm::BasicBlock const*> >&) const'
collect2: error: ld returned 1 exit status
src/CMakeFiles/llvm-prof.dir/build.make:147: recipe for target 'src/llvm-prof' failed
make[2]: *** [src/llvm-prof] Error 1
CMakeFiles/Makefile2:201: recipe for target 'src/CMakeFiles/llvm-prof.dir/all' failed
make[1]: *** [src/CMakeFiles/llvm-prof.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
Any idea about what I am doing wrong or how can I solve the problem?
Thanks!
I'm currently using LLVM version 3.5.2.
Do you expect that this version should work?
Thank you very much!
Yes but it didn' help( cmake LLVM_RECOMMEND_VERSION=3.5.2 ..
).
I also modified, by hand, the auto-generated build/src/CMakeFiles/llvm-prof.dir/link.txt
file by adding the -ldl
flag:
/usr/bin/g++-4.8 CMakeFiles/llvm-prof.dir/llvm-prof.cpp.o CMakeFiles/llvm-prof.dir/printer.cpp.o CMakeFiles/llvm-prof.dir/passes.cpp.o -o llvm-prof -L/local_disk/cornagli/llvmTracer/llvm3.5Auto/lib -rdynamic -lLLVMAnalysis -lLLVMTarget -lLLVMMC -lLLVMBitReader -lLLVMCore -lLLVMSupport ../lib/libLLVMProfiling.so -pthread -ltinfo -ldl -Wl,-rpath,/local_disk/cornagli/llvmTracer/llvm3.5Auto/lib:/local_disk/cornagli/llvm-prof/llvm-prof/build/lib:
Now the error showed by the make
command is:
[ 36%] Built target LLVMProfiling-static
[ 73%] Built target LLVMProfiling-shared
[ 75%] Linking CXX executable llvm-prof
../lib/libLLVMProfiling.so: undefined reference to `llvm::Statistic::RegisterStatistic()'
../lib/libLLVMProfiling.so: undefined reference to `llvm::LoopInfo::ID'
../lib/libLLVMProfiling.so: undefined reference to `llvm::LoopInfoBase<llvm::BasicBlock, llvm::Loop>::getLoopFor(llvm::BasicBlock const*) const'
../lib/libLLVMProfiling.so: undefined reference to `llvm::LoopInfoBase<llvm::BasicBlock, llvm::Loop>::isLoopHeader(llvm::BasicBlock*) const'
../lib/libLLVMProfiling.so: undefined reference to `llvm::LoopBase<llvm::BasicBlock, llvm::Loop>::contains(llvm::BasicBlock const*) const'
../lib/libLLVMProfiling.so: undefined reference to `llvm::SplitCriticalEdge(llvm::TerminatorInst*, unsigned int, llvm::Pass*, bool, bool, bool)'
../lib/libLLVMProfiling.so: undefined reference to `llvm::LoopBase<llvm::BasicBlock, llvm::Loop>::getLoopLatch() const'
../lib/libLLVMProfiling.so: undefined reference to `llvm::LoopBase<llvm::BasicBlock, llvm::Loop>::getExitEdges(llvm::SmallVectorImpl<std::pair<llvm::BasicBlock const*, llvm::BasicBlock const*> >&) const'
collect2: error: ld returned 1 exit status
src/CMakeFiles/llvm-prof.dir/build.make:147: recipe for target 'src/llvm-prof' failed
make[2]: *** [src/llvm-prof] Error 1
CMakeFiles/Makefile2:201: recipe for target 'src/CMakeFiles/llvm-prof.dir/all' failed
make[1]: *** [src/CMakeFiles/llvm-prof.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
cmake .. -DLLVM_RECOMMEND_VERSION=3.5
you set VERSION is for lookup llvm-config-3.5
so, there are not llvm-config-3.5.2 at all.
tested ubuntu 16.04.2 just minutes ago
xiehuc@virtualbox:~/llvm/llvm-prof-master/build$ ls lib/
CMakeFiles cmake_install.cmake datatype datatype.h libLLVMProfiling.a libLLVMProfiling.so Makefile