编译PJSIP Android .so文件时遇features.h及链接错误求助
Let's break down your issues one by one and walk through concrete fixes step by step—since you're new to Android native development, I'll keep things as straightforward as possible.
1. Fixing the 'features.h' not found error in Windows 10 Ubuntu Bash (WSL)
The features.h file is part of the GNU C library, so this error typically pops up when your WSL environment is missing essential build dependencies, or your Android NDK configuration is misaligned. Here's how to fix it:
- First, install the core build tools and libraries in your WSL Ubuntu instance:
sudo apt-get update && sudo apt-get install build-essential libc6-dev - Double-check that you're using a compatible NDK version. Since you need to support the
armeabiarchitecture (which was deprecated in newer NDKs), stick with NDK r17c or r18b—newer versions (r19+) no longer supportarmeabi. - When re-running the
configure-androidscript, make sure you explicitly point to your cross-compiled OpenSSL build (not the system-installed OpenSSL on your WSL host). For example:./configure-android --with-ssl=/path/to/your/openssl-1.1.1-pre6-android/armeabi-v7a - Before running
make, runmake clean && make depto ensure no stale build files are causing conflicts.
2. Fixing OpenSSL linking errors in VirtualBox Ubuntu
Linking errors almost always boil down to one of three issues: mismatched architectures, incorrect OpenSSL paths, or missing cross-compiled OpenSSL libraries. Let's address each:
Step 1: Ensure you're cross-compiling OpenSSL for the correct Android architecture
You can't use a single OpenSSL build for all four architectures—you need to compile OpenSSL separately for each target. Here's a working example for armeabi-v7a (adjust variables for other architectures):
# Set up NDK paths and toolchain variables export ANDROID_NDK=/path/to/your/ndk-r17c export PATH=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin:$PATH export AR=arm-linux-androideabi-ar export CC=armv7a-linux-androideabi19-clang export CXX=armv7a-linux-androideabi19-clang++ export LD=arm-linux-androideabi-ld export RANLIB=arm-linux-androideabi-ranlib export STRIP=arm-linux-androideabi-strip # Configure and build OpenSSL cd /path/to/openssl-1.1.1-pre6 ./Configure android-arm -D__ANDROID_API__=19 --prefix=/path/to/output/openssl-armeabi-v7a make clean make make install
- For
armeabi: Useandroidinstead ofandroid-armin theConfigurecommand, and setCC=arm-linux-androideabi16-clang(API level 16 is the minimum for armeabi). - For
arm64-v8a: Useandroid-arm64, setCC=aarch64-linux-android21-clang(API level 21 minimum), and adjust other tools toaarch64-linux-android-*. - For
x86: Useandroid-x86, setCC=i686-linux-android16-clang, and tools toi686-linux-android-*.
Step 2: Configure PJSIP with the correct architecture-specific OpenSSL path
When configuring PJSIP, explicitly target the architecture and point to the matching OpenSSL build:
cd /path/to/pjsip ./configure-android --target=armeabi-v7a --with-ssl=/path/to/output/openssl-armeabi-v7a
Step 3: Debug linking errors with verbose output
If you still get linking errors, run make with verbose mode to see exactly what's going wrong:
make VERBOSE=1
This will show you the full linker command—check if it's including the -L/path/to/openssl/lib flag and linking against libssl.so and libcrypto.so. If not, you may need to adjust the configure-android flags or verify that your OpenSSL build actually generated those libraries.
Quick Pre-Checks to Avoid Headaches
- Never use host OpenSSL: Always cross-compile OpenSSL for Android—using the system OpenSSL on your Ubuntu machine will cause architecture mismatches.
- Clean builds: Always run
make cleanbefore reconfiguring or rebuilding to avoid stale files from previous attempts. - Verify architecture compatibility: Use the
filecommand to check your compiled libraries. For example, anarmeabi-v7alibssl.soshould show:ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked.
Once you get one architecture working, repeat the same steps for the other three (armeabi, arm64-v8a, x86) to generate all required .so files.
内容的提问来源于stack exchange,提问作者Priya Sindkar

