7.2 KiB
Executable File
Prerequisites
Preparing OpenHarmony SDK
OpenHarmony provides SDKs for Linux, Windows, and macOS platforms, enabling cross-compilation across these systems. This guide focuses on Linux-based cross-compilation.
-
Download the SDK for your target platform from the official release channel.
-
Extract the SDK package:
owner@ubuntu:~/workspace$ tar -zxvf ohos-sdk-windows_linux-public.tar.gz -
Navigate to the SDK's Linux directory and extract all toolchain packages:
owner@ubuntu:~/workspace$ cd ohos_sdk/linux owner@ubuntu:~/workspace/ohos-sdk/linux$ for i in *.zip;do unzip ${i};done owner@ubuntu:~/workspace/ohos-sdk/linux$ ls total 1228400 85988 -rw-r--r-- 1 wshi wshi 88050148 Nov 20 2024 ets-linux-x64-5.0.1.111-Release.zip # ArkTS compiler tools 56396 -rw-r--r-- 1 wshi wshi 57747481 Nov 20 2024 js-linux-x64-5.0.1.111-Release.zip # JS compiler tools 888916 -rw-r--r-- 1 wshi wshi 910243125 Nov 20 2024 native-linux-x64-5.0.1.111-Release.zip # C/C++ cross-compilation tools 175084 -rw-r--r-- 1 wshi wshi 179281763 Nov 20 2024 previewer-linux-x64-5.0.1.111-Release.zip # App preview tools 22008 -rw-r--r-- 1 wshi wshi 22533501 Nov 20 2024 toolchains-linux-x64-5.0.1.111-Release.zip # Utilities (e.g., signing tool, device connector)
Once you extract these 5 archives, the SDK setup will be complete, and its path will be ~/workspace/ohos-sdk/linux.
Compiling resiprocate 1.13 and later versions
Compared to earlier versions, resiprocate 1.13 switched its build system to CMake. The OpenHarmony SDK provides full support for CMake, making cross-compilation tasks easy to accomplish.
Obtaining the Source Code
Download the resiprocate-1.13.2 source code package from GitHub and extract it to ~/workspace/resiprocate.
tar -zxvf resiprocate-1.13.2.tar.gz -C ~/workspace/resiprocate
Starting the Compilation
-
Set the SDK path
owner@ubuntu:~/workspace/resiprocate$ export OHOS_SDK=/home/owner/workspace/ohos-sdk/linux ## Configure the SDK path. Replace this with your own SDK decompression directory. owner@ubuntu:~/workspace/resiprocate$ export PATH=$OHOS_SDK/native/build-tools/cmake/bin:$PATH ## Add the SDK's cmake to the PATH environment variable -
Execute cmake to generate Makefile
By default, the 64-bit version is compiled. If the 32-bit version is needed, set
OHOS_ARCHtoarmeabi-v7a.CMAKE_INSTALL_PREFIXis set to/home/owner/install/resiprocate, which is the installation directory for cross-compiled outputs.owner@ubuntu:~/workspace/resiprocate$ cmake . -DCMAKE_TOOLCHAIN_FILE=$OHOS_SDK/native/build/cmake/ohos.toolchain.cmake -DWITH_SSL=OFF -DUSE_DTLS=OFF -DWITH_C_ARES=OFF -DBUILD_QPID_PROTON=OFF -DRESIP_ASSERT_SYSLOG=OFF -DREGENERATE_MEDIA_SAMPLES=OFF -DBUILD_DSO_PLUGINS=OFF -DUSE_POPT=OFF -DUSE_MAXMIND_GEOIP=OFF -DBUILD_REPRO=OFF -DBUILD_RETURN=OFF -DBUILD_RECON=OFF -DBUILD_REFLOW=OFF -DBUILD_REND=OFF -DBUILD_TFM=OFF -DUSE_KURENTO=OFF -DHAVE_CLOCK_GETTIME_MONOTONIC=ON -DCMAKE_INSTALL_PREFIX=/home/owner/install/resiprocateHere, all optional compilation options in cmake are disabled. If needed, you can cross-compile the corresponding third-party libraries for OpenHarmony, set their paths in
CMAKE_FIND_ROOT_PATH, and then enable the relevant compilation options.Due to cross-compilation, the
try_run()forHAVE_CLOCK_GETTIME_MONOTONICin the cmake script will fail. Therefore, the test result is passed to the cmake script via a parameter here. -
Execute the
makecommand:
After a successful cmake, run make to start cross-compilation:
owner@ubuntu:~/workspace/resiprocate$ make # Run the make command to compile
-
Execute the installation command:
owner@ubuntu:~/workspace/resiprocate$ make installAfter installation, the cross-compiled resiprocate library files can be found in the installation directory
/home/owner/install/resiprocate.
Compiling resiprocate versions prior to 1.13
Obtaining the Source Code
Download the resiprocate-1.12.0 source code package from GitHub and extract it to ~/workspace/resiprocate.
tar -zxvf resiprocate-1.12.0.tar.gz -C ~/workspace/resiprocate
Starting the Compilation
-
Set the toolchain path:
export OHOS_SDK=/home/owner/workspace/ohos-sdk/linux ## Configure the SDK path. Replace this with your own SDK extraction directory. export AS=${OHOS_SDK}/native/llvm/bin/llvm-as export CC="${OHOS_SDK}/native/llvm/bin/clang --target=aarch64-linux-ohos" ## For 32-bit targets, use --target=arm-linux-ohos export CXX="${OHOS_SDK}/native/llvm/bin/clang++ --target=aarch64-linux-ohos" ## For 32-bit targets, use --target=arm-linux-ohos export LD=${OHOS_SDK}/native/llvm/bin/ld.lld export STRIP=${OHOS_SDK}/native/llvm/bin/llvm-strip export RANLIB=${OHOS_SDK}/native/llvm/bin/llvm-ranlib export OBJDUMP=${OHOS_SDK}/native/llvm/bin/llvm-objdump export OBJCOPY=${OHOS_SDK}/native/llvm/bin/llvm-objcopy export NM=${OHOS_SDK}/native/llvm/bin/llvm-nm export AR=${OHOS_SDK}/native/llvm/bin/llvm-ar export CFLAGS="-fPIC -D__MUSL__=1" ## For 32-bit, add -march=armv7a export CXXFLAGS="-fPIC -D__MUSL__=1" ## For 32-bit, add -march=armv7a -
Execute the
autoreconfcommand:The resiprocate source code root directory does not contain a
configurefile. Runautoreconfin the root directory to generate it:owner@ubuntu:~/workspace/resiprocate$ autoreconf -ifv -
Execute the
configurecommand:Once generated, run the
configurescript to create the Makefile. The following example configures for ARM64. For 32-bit, replaceaarch64-linuxwitharm-linux. Theprefixis set to/home/owner/install/resiprocate, which is the installation directory for the cross-compiled output.owner@ubuntu:~/workspace/resiprocate$ ./configure --prefix=/home/owner/install/resiprocate --host=aarch64-linux # Run the configure command to set up cross-compilation -
Execute the
makecommand:
After a successful configure, run make to start cross-compilation:
owner@ubuntu:~/workspace/resiprocate$ make # Run the make command to compile
-
Execute the installation command:
owner@ubuntu:~/workspace/resiprocate$ make installAfter installation, the cross-compiled resiprocate library files can be found in the installation directory
/home/owner/install/resiprocate.