Static Linking and loading "libclang.so"

Hey.

I’ve compiled llvm/clang with arm-linux-gnueabi toolchain:

BUILD=/home/asmirnov/llvm_33_arm_build_gnueabi_cmake
rm -rf $BUILD
mkdir $BUILD
cd $BUILD

cmake …/llvm_33 -DCMAKE_C_COMPILER=arm-linux-gnueabi-gcc -DCMAKE_CXX_COMPILER=arm-linux-gnueabi-g++ -DCMAKE_CROSSCOMPILING=True -DLLVM_TABLEGEN=/home/asmirnov/llvm_33_build/Release+Asserts/bin/llvm-tblgen -DLLVM_DEFAULT_TARGET_TRIPLE=arm-linux-gnueabi -DLLVM_TARGET_ARCH=ARM -DLLVM_TARGETS_TO_BUILD=ARM -DCMAKE_SYSTEM_NAME=Linux -DCMAKE_BUILD_TYPE=Release

When i try to load library libclang.so.3.3 on android (linux), i’m getting an error:

Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: link_image[1891]: 185 could not load needed library ‘libdl.so.2’ for ‘libclang.so.3.3’ (load_library[1093]: Library ‘libdl.so.2’ not found)

The sources are extracted for clang release 3.3 (llvm, compiler-rt and clang). The build type is “Release”. So what should i do in order to link it statically (or walk-around lib absence)?

PS. “libclang.so.3.3” file size is about 14mb.

Regards, Anton.

The same problem if i recompile is in Debug mode and libclang.so is about 48Mb.

Any thoughts?

Hi Anton,

libdl is required (as others) and probably not installed in your target
system. You should be able to install it via yum/apt-get etc.

Installing Clang via packages would probably bring that dependency
automatically, but you compiled it from scratch on a separate machine, so
dependencies won't be met automatically.

And, yes, Clang/LLVM libraries are huge, especially ones with debug symbols
in it.

cheers,
--renato

As target system is Android i can’t just add packages without rooting which is not desired.
That’s why i’d like to link libclang statically in order to have all dependencies within .so.

Is it possible?

I’ve found /system/lib/libdl.so on my android device. So i wonder why it’s not found and loaded.
Does the fact that i’m compiling on linux 64bit but it’s running on linux 32bit (android) affect this?

I've found /system/lib/libdl.so on my android device. So i wonder why it's
not found and loaded.

That's a good question. I'm not familiar with Android, so I can't answer
that. Maybe you'll have more luck on an Android forum?

Does the fact that i'm compiling on linux 64bit but it's running on linux
32bit (android) affect this?

It shouldn't.

--renato

Hi,

Note that there may be a slightly different issue: to my understanding Android actually provides a lot of the system calls expected of a Unix-y environment, but often puts them in different libraries. (At the very least, it looks like the linker is looking directly for libdl.so.2, which may not be the version used on Android, or as mentioned the functionality LLVM wants may actually be resident in a different .so file). However, I’m not remotely expert of the intricacies of Android, so I’ll leave further advice for someone who’s actually built LLVM for Android J (In the worst case that no-one has done this you may have to figure out the dependencies and change the LLVM build-files yourself.)

Cheers,
Dave