makefile方式

脚本如下:

deal.sh

#!/bin/sh
llvm_path="/opt/ohos-sdk/linux/native/llvm/bin/"
arch=$1
make clean

export AR="${llvm_path}/llvm-ar"
export STRIP="${llvm_path}/llvm-strip"
export RANLIB="${llvm_path}/llvm-ranlib"
if [[ $arch = "arm64" ]]; then
	export CC="${llvm_path}/aarch64-unknown-linux-ohos-clang"
	export CXX="${llvm_path}/aarch64-unknown-linux-ohos-clang++"
	## 设置编译标志
	export CFLAGS="--target=aarch64-unknown-linux-ohos -Wl,--no-as-needed"
	export CXXFLAGS="--target=aarch64-unknown-linux-ohos -Wl,--no-as-needed"
elif [[ $arch = "arm" ]]; then
	export CC="${llvm_path}/armv7-unknown-linux-ohos-clang"
	export CXX="${llvm_path}/armv7-unknown-linux-ohos-clang++"
	
	## 设置编译标志
	export CFLAGS="--target=arm-linux-ohos -Wl,--no-as-needed"
	export CXXFLAGS="--target=arm-linux-ohos -Wl,--no-as-needed"
fi

make -j12

执行:

chmod +x deal.sh

./deal.sh arm 或者./deal.sh arm64

cmake方式:

armv7:

cmake -DCMAKE_TOOLCHAIN_FILE=/opt/ohos-sdk/linux/native/build/cmake/ohos.toolchain.cmake -S . -B build -DOHOS_ARCH=armeabi-v7a

cd build && make

armv8:

cmake -DCMAKE_TOOLCHAIN_FILE=/opt/ohos-sdk/linux/native/build/cmake/ohos.toolchain.cmake -S . -B build -DOHOS_ARCH=armv64-v8a

cd build && make

 

Logo

社区规范:仅讨论OpenHarmony相关问题。

更多推荐