ossrs / srs

SRS is a simple, high-efficiency, real-time video server supporting RTMP, WebRTC, HLS, HTTP-FLV, SRT, MPEG-DASH, and GB28181.
https://ossrs.io
MIT License
25.16k stars 5.31k forks source link

Build: Support cross build toolchain with clang/clang++ #3713

Open terrencetang2023 opened 1 year ago

terrencetang2023 commented 1 year ago

Note: Please read FAQ before file an issue, see #2716

Description

When the cross-compilation tool uses clang/clang++, gcc/g++ is forcibly appended, please add the judgment condition of the clang tool

  1. SRS Version: v6.0-d0

  2. SRS Log:

For cross build, host: /data/local/ohos-sdk/linux/native/llvm/bin/arm-linux-ohos-clang, prefix: /data/local/ohos-sdk/linux/native/llvm/bin/arm-linux-ohos-clang-, arch: arm, cpu:  gcc: /data/local/ohos-sdk/linux/native/llvm/bin/arm-linux-ohos-clang-gcc
Enable FFmpeg native opus for cross building
Enable asan by auto options.
User config: --prefix=/home/tangshaoteng/codes/gitee_priv/lycium_back/usr/srs/armeabi-v7a --cross-build --cc=/data/local/ohos-sdk/linux/native/llvm/bin/arm-linux-ohos-clang --cxx=/data/local/ohos-sdk/linux/native/llvm/bin/arm-linux-ohos-clang++ --ar=/data/local/ohos-sdk/linux/native/llvm/bin/llvm-ar --ld=/data/local/ohos-sdk/linux/native/llvm/bin/ld.lld --randlib=/data/local/ohos-sdk/linux/native/llvm/bin/llvm-ranlib --backtrace=off
Detail config: --prefix=/home/tangshaoteng/codes/gitee_priv/lycium_back/usr/srs/armeabi-v7a --config=conf/srs.conf --osx=off --hls=on --hds=off --dvr=on --ssl=on --https=on --ssl-1-0=off --ssl-local=off --sys-ssl=off --transcode=on --ingest=on --stat=on --http-callback=on --http-server=on --stream-converter=on --http-api=on --utest=off --srt=on --rtc=on --h265=off --gb28181=off --simulator=off --cxx11=on --cxx14=off --backtrace=off --ffmpeg-fit=on --ffmpeg-opus=on --nasm=on --srtp-nasm=on --clean=on --gperf=off --gmc=off --gmd=off --gmp=off --gcp=off --gprof=off --static=off --shared-st=off --shared-srt=off --shared-ffmpeg=off --log-verbose=off --log-info=off --log-trace=on --log-level_v2=on --gcov=off --apm=off --debug=off --debug-stats=off --cross-build=on --sanitizer=on --sanitizer-static=off --sanitizer-log=off --cygwin64=off --single-thread=off --generic-linux=off --arch=arm --host=/data/local/ohos-sdk/linux/native/llvm/bin/arm-linux-ohos-clang --cross-prefix=/data/local/ohos-sdk/linux/native/llvm/bin/arm-linux-ohos-clang- --cc=/data/local/ohos-sdk/linux/native/llvm/bin/arm-linux-ohos-clang-gcc --cxx=/data/local/ohos-sdk/linux/native/llvm/bin/arm-linux-ohos-clang-g++ --ar=/data/local/ohos-sdk/linux/native/llvm/bin/arm-linux-ohos-clang-ar --ld=/data/local/ohos-sdk/linux/native/llvm/bin/arm-linux-ohos-clang-ld --randlib=/data/local/ohos-sdk/linux/native/llvm/bin/arm-linux-ohos-clang-randlib
Discover SRS version=6.0.59, major=6
SRS_WORKDIR: ., SRS_OBJS: ./objs, SRS_PLATFORM: Platform-SRS6-Linux-5.15.0-GCC9.4.0-x86_64-crossbuild-arm-linux
All outputs to: ./objs/Platform-SRS6-Linux-5.15.0-GCC9.4.0-x86_64-crossbuild-arm-linux
Alias python2 as python
SRS_JOBS: --jobs=8, SRS_DEPENDS_LIBS: /home/tangshaoteng/codes/gitee_priv/lycium_back/main/srs/srs-server-6.0-d0-armeabi-v7a-build/trunk/objs, OS_IS_LINUX: YES, OS_IS_UBUNTU: YES, SRS_CROSS_BUILD: YES, OS_IS_X86_64: YES
link static-libasan
libasan api found ok!
Building state-threads.
make: Entering directory '/home/tangshaoteng/codes/gitee_priv/lycium_back/main/srs/srs-server-6.0-d0-armeabi-v7a-build/trunk/objs/Platform-SRS6-Linux-5.15.0-GCC9.4.0-x86_64-crossbuild-arm-linux/st-srs
make OS="LINUX" BUILD="DBG"
make[1]: Entering directory '/home/tangshaoteng/codes/gitee_priv/lycium_back/main/srs/srs-server-6.0-d0-armeabi-v7a-build/trunk/objs/Platform-SRS6-Linux-5.15.0-GCC9.4.0-x86_64-crossbuild-arm-linux/st-srs
if [ ! -d LINUX_5.15.0-76-generic_DBG ]; then mkdir LINUX_5.15.0-76-generic_DBG; fi
/data/local/ohos-sdk/linux/native/llvm/bin/arm-linux-ohos-clang-gcc  -DLINUX -DMD_HAVE_EPOLL -DMD_HAVE_SELECT -DDEBUG -Wall -g -O0 -DMALLOC_STACK -DMD_HAVE_EPOLL  -c sched.c -o LINUX_5.15.0-76-generic_DBG/sched.o
make[1]: /data/local/ohos-sdk/linux/native/llvm/bin/arm-linux-ohos-clang-gcc: command not found
make[1]: *** [Makefile:283: LINUX_5.15.0-76-generic_DBG/sched.o] Error 127
make[1]: Leaving directory '/home/tangshaoteng/codes/gitee_priv/lycium_back/main/srs/srs-server-6.0-d0-armeabi-v7a-build/trunk/objs/Platform-SRS6-Linux-5.15.0-GCC9.4.0-x86_64-crossbuild-arm-linux/st-srs'
make: *** [Makefile:310: linux-debug] Error 2
make: Leaving directory '/home/tangshaoteng/codes/gitee_priv/lycium_back/main/srs/srs-server-6.0-d0-armeabi-v7a-build/trunk/objs/Platform-SRS6-Linux-5.15.0-GCC9.4.0-x86_64-crossbuild-arm-linux/st-srs
Build state-threads failed, ret=2
make: *** No target specified and no makefile found. Stop.
  1. SRS Config:

Replay

Please describe how to replay the bug?

Step 1: run configure

./configure --cross-build --cc=${OHOS_SDK}/native/llvm/bin/arm-linux-ohos-clang --cxx=${OHOS_SDK}/native/llvm/bin/arm-linux-ohos-clang++ --ar=${OHOS_SDK}/native/llvm/bin/llvm-ar --ld=${OHOS_SDK}/native/llvm/bin/ld.lld --randlib=${OHOS_SDK}/native/llvm/bin/llvm-ranlib

Step 2: make

make

Expect

It is expected to add clang/clang++ support in cross-compilation environments

TRANS_BY_GPT3

terrencetang2023 commented 1 year ago

error: /data/local/ohos-sdk/linux/native/llvm/bin/arm-linux-ohos-clang-gcc not found

winlinvip commented 4 months ago

To support cross build, SRS extract the --cross-prefix from --cc, which only support gcc right now:

        if [[ $SRS_CROSS_BUILD_PREFIX != "" && $SRS_CROSS_BUILD_HOST == "" ]]; then
            SRS_CROSS_BUILD_HOST=$(echo $SRS_CROSS_BUILD_PREFIX| sed 's/-$//g')
        fi
        if [[ $SRS_TOOL_CC != "" && $SRS_CROSS_BUILD_HOST == "" ]]; then
            SRS_CROSS_BUILD_HOST=$(echo $SRS_TOOL_CC| sed 's/-gcc$//g')
        fi
        if [[ $SRS_CROSS_BUILD_PREFIX == "" ]]; then
            SRS_CROSS_BUILD_PREFIX="${SRS_CROSS_BUILD_HOST}-"
        fi
        SRS_TOOL_CC=${SRS_CROSS_BUILD_PREFIX}gcc

So there is a workaround, to specify the prefix and cc, for example:

--cross-prefix=/data/local/ohos-sdk/linux/native/llvm/bin/arm-linux-ohos- \
--cc=clang

Welcome to help to improve the auto/options.sh script to support clang.