Clang for ARM

Hello, I’ve almost compiled Clang for ARM, but i’ve an error
in the end:

[ 84%] Built target clangRewriteFrontend
[ 86%] Built target clangARCMigrate
[ 86%] Built target ClangSACheckers
[ 89%] Built target clangStaticAnalyzerCore
[ 94%] Built target clangStaticAnalyzerCheckers
[ 95%] Built target clangStaticAnalyzerFrontend
[ 95%] Built target clangFrontendTool
[ 95%] Built target clangTooling
[ 95%] Built target clangFormat
[ 97%] Built target libclang
[ 98%] Built target libclang_static
Linking CXX executable …/…/…/…/bin/c-index-test
/home/asmirnov/arm-toolchain-clang33/bin/arm-linux-androideabi-ld: …/…/…/…/lib/libclang.so.3.3: error: undefined reference to ‘dladdr’
clang33: error: linker command failed with exit code 1 (use -v to see invocation)

I’ve found similar question with solution:
http://stackoverflow.com/questions/12993460/why-am-i-getting-undefined-reference-to-dladdr-even-with-ldl-for-this-simpl

So i wonder what should i do and is it bug or my dev env issue?

Anton.

Linking CXX executable ../../../../bin/c-index-test
/home/asmirnov/arm-toolchain-clang33/bin/arm-linux-androideabi-ld:
../../../../lib/libclang.so.3.3: error: undefined reference to 'dladdr'
clang33: error: linker command failed with exit code 1 (use -v to see
invocation)

Hi Anton,

I'm intrigued why are you using the androideabi linker...

I've found similar question with solution:

http://stackoverflow.com/questions/12993460/why-am-i-getting-undefined-reference-to-dladdr-even-with-ldl-for-this-simpl

So i wonder what should i do and is it bug or my dev env issue?

Did you try the solution in that question?

cheers,
--renato

It sounds like Android might put libdl in an odd place, though I've
never tried to build for it. You might have to tell CMake about this
location before it will work.

Anton: running "make VERBOSE=1" will show the actual command-line
that's failing. That could shed some light on what's going on (e.g.
whether -ldl is completely missing or just in the wrong place).

Did you try the solution in that question?

Even I wouldn't know how to do that. This is LLVM's own build system.
Set CMAKE_CXX_FLAGS? Set CMAKE_EXE_LINKER_FLAGS?

Cheers.

Tim.

Hey, guys.

I’m using androideabi linker as i’m compiling for android (ARM Linux).

thanks for verbose flag tip, i’ve tried and output is pretty largeso dive in it if you have time and wish:

/home/asmirnov/arm-toolchain-clang33/bin/arm-linux-androideabi-clang++ -target arm-linux-androideabi -mcpu=cortex-a9 -I/home/asmirnov/android-ndk-r9/platforms/android-8/arch-arm/include -I/home/asmirnov/android-ndk-r9/platforms/android-8/arch-arm/usr/include -mfloat-abi=soft -ccc-gcc-name arm-linux-androideabi -fPIC -fvisibility-inlines-hidden -Wall -W -Wno-unused-parameter -Wwrite-strings -Wmissing-field-initializers -pedantic -Wno-long-long -Wcovered-switch-default -Wnon-virtual-dtor -fno-common -Woverloaded-virtual -Wcast-qual -fno-strict-aliasing -Wno-nested-anon-types -fno-rtti -ldl CMakeFiles/c-index-test.dir/c-index-test.c.o -o …/…/…/…/bin/c-index-test -L/home/asmirnov/arm-toolchain-clang33/lib/gcc/arm-linux-androideabi/4.6 -L/home/asmirnov/arm-toolchain-clang33/arm-linux-androideabi/lib -L/home/asmirnov/arm-toolchain-clang33/sysroot/usr/lib …/…/…/…/lib/libLLVMMC.a …/…/…/…/lib/libLLVMObject.a …/…/…/…/lib/libLLVMSupport.a -ldl -lz …/…/…/…/lib/libclang.so.3.3 …/…/…/…/lib/libclangARCMigrate.a …/…/…/…/lib/libclangFormat.a …/…/…/…/lib/libclangTooling.a …/…/…/…/lib/libclangRewriteFrontend.a …/…/…/…/lib/libclangRewriteCore.a …/…/…/…/lib/libclangFrontend.a …/…/…/…/lib/libclangDriver.a …/…/…/…/lib/libclangSerialization.a …/…/…/…/lib/libLLVMBitReader.a …/…/…/…/lib/libclangParse.a …/…/…/…/lib/libclangSema.a …/…/…/…/lib/libLLVMARMCodeGen.a …/…/…/…/lib/libLLVMARMAsmParser.a …/…/…/…/lib/libLLVMARMDisassembler.a …/…/…/…/lib/libLLVMAsmParser.a …/…/…/…/lib/libLLVMAsmPrinter.a …/…/…/…/lib/libLLVMSelectionDAG.a …/…/…/…/lib/libLLVMARMDesc.a …/…/…/…/lib/libLLVMMCParser.a …/…/…/…/lib/libLLVMCodeGen.a …/…/…/…/lib/libLLVMARMAsmPrinter.a …/…/…/…/lib/libLLVMARMInfo.a …/…/…/…/lib/libLLVMObjCARCOpts.a …/…/…/…/lib/libLLVMScalarOpts.a …/…/…/…/lib/libLLVMInstCombine.a …/…/…/…/lib/libLLVMTransformUtils.a …/…/…/…/lib/libLLVMipa.a …/…/…/…/lib/libLLVMAnalysis.a …/…/…/…/lib/libLLVMTarget.a …/…/…/…/lib/libLLVMCore.a …/…/…/…/lib/libclangEdit.a …/…/…/…/lib/libclangAnalysis.a …/…/…/…/lib/libclangASTMatchers.a …/…/…/…/lib/libclangAST.a …/…/…/…/lib/libclangLex.a …/…/…/…/lib/libclangBasic.a …/…/…/…/lib/libLLVMMC.a …/…/…/…/lib/libLLVMObject.a …/…/…/…/lib/libLLVMSupport.a -ldl -lz -ldl -lc -ldl -Wl,-rpath,/home/asmirnov/llvm_arm_build/lib
/home/asmirnov/arm-toolchain-clang33/bin/arm-linux-androideabi-ld: …/…/…/…/lib/libclang.so.3.3: error: undefined reference to ‘dladdr’
clang33: error: linker command failed with exit code 1 (use -v to see invocation)

I will keep trying to solve it but your help is appreciated too.
thank you.

PS. Actually my current cmake command-line is:

CC=“arm-linux-androideabi-clang” CXX=“arm-linux-androideabi-clang++” PATH=/home/asmirnov/arm-toolchain-clang33:${PATH} cmake …/llvm -DCMAKE_CROSSCOMPILING=True -DCMAKE_INSTALL_PREFIX=/home/asmirnov/llvm_arm_installed -DLLVM_DEFAULT_TARGET_TRIPLE=arm-linux-androideabi -DLLVM_TARGET_ARCH=ARM -DLLVM_TARGETS_TO_BUILD=ARM -DLLVM_TABLEGEN=/home/asmirnov/llvm_host_build/Release+Asserts/bin/llvm-tblgen -DCLANG_TABLEGEN=/home/asmirnov/llvm_host_build/Release+Asserts/bin/clang-tblgen -DCMAKE_CXX_FLAGS=’-target arm-linux-androideabi -mcpu=cortex-a9 -I/home/asmirnov/android-ndk-r9/platforms/android-8/arch-arm/include -I/home/asmirnov/android-ndk-r9/platforms/android-8/arch-arm/usr/include -mfloat-abi=soft -ccc-gcc-name arm-linux-androideabi’

I’m using standalone toolchain from android ndk (clang 3.3)

http://stackoverflow.com/questions/12993460/why-am-i-getting-undefined-reference-to-dladdr-even-with-ldl-for-this-simpl

So i wonder what should i do and is it bug or my dev env issue?

Did you try the solution in that question?

I did not actually catch what should i do.
Should i just run `llvm-config --libs core` `llvm-config --ldflags` before
"make"?

No, that's what's going to get the Makefile in the right order. If you run
it manually, you won't change anything.

What's the answer is trying to say is that llvm-config is getting -ldl in
the wrong order, so the line that generates the LDFLAGS should call
llvm-config twice (in that order), instead of once, as it's probably doing
it now.

To make sure this is, indeed, a solution, I recommend you to look into the
Makefile/Ninja rules, to see what is the generated order of libraries, and
if -ldl appears before or after LLVMSupport. If you change the Make/Ninja
file and it works, means the call to llvm-config is bad, and this needs to
be fixed in llvm-config itself, at least for the Android case.

cheers,
--renato