|
| 1 | +--- |
| 2 | +title: ARM and CrossBuild |
| 3 | +sidebar_label: ARM和交叉编译 |
| 4 | +hide_title: false |
| 5 | +hide_table_of_contents: false |
| 6 | +--- |
| 7 | + |
| 8 | +# SRS for linux-arm |
| 9 | + |
| 10 | +注意:一般情况下,直接在<code>ARM</code>下是可以编译SRS的,参考官网正常的编译方法就可以,不需要交叉编译。 |
| 11 | + |
| 12 | +!!! 注意,请先确认是否需要<code>交叉编译</code>,一般可以直接编译,除非极少数情况。 |
| 13 | + |
| 14 | +> 翁晓晶:看来很多人误解了交叉编译的意思了,异构平台编译才要,比如编译平台跟运行平台是异构的,才需要,都是同一个平台不需要。 |
| 15 | +
|
| 16 | +> 翁晓晶:最常见的场景就是玩网络设备的,因为网络设备的u都很弱,编译很慢,所以才在pc上做交叉编译,因为pc的u是x86,网络设备的u基本上都是mips或者arm的低频率的,属于异构,x86的u编译速度明显快于它们,所以大家都在pc上做交叉编译,然后把结果拷贝进网络设备,这样编译速度快很多,当然你有时间也可以直接在网络设备上正常编译也是可以的,就是慢很多。 |
| 17 | +
|
| 18 | +> 翁晓晶:我看到有个朋友提到arm的服务器比如鲲鹏,那就直接在arm的服务器上编译就好了,没必要再交叉编译了,arm服务器又不是网络设备,U编译个程序还是没问题的,不要走弯路了。 |
| 19 | +
|
| 20 | +## Why run SRS on ARM? |
| 21 | + |
| 22 | +ARM跑SRS主要原因: |
| 23 | + |
| 24 | +* ARM服务器越来越多了,可以直接编译和运行SRS,参考 [#1282](https://github.com/ossrs/srs/issues/1282#issue-386077124)。 |
| 25 | +* ARM嵌入式设备上用SRS,会比较难,但可以交叉编译,参考 [#1547](https://github.com/ossrs/srs/issues/1547#issue-543780097)。 |
| 26 | + |
| 27 | +## RaspberryPi |
| 28 | + |
| 29 | +SRS可以直接在`RespberryPI`上编译和运行,不用交叉编译。参考 [#1282](https://github.com/ossrs/srs/issues/1282#issue-386077124)。 |
| 30 | + |
| 31 | +<a name="armv8-and-aarch64"></a> |
| 32 | + |
| 33 | +## ARM Server: armv7, armv8(aarch64) |
| 34 | + |
| 35 | +SRS可以直接在ARM Server上编译和运行,不用交叉编译。参考 [#1282](https://github.com/ossrs/srs/issues/1282#issue-386077124)。 |
| 36 | + |
| 37 | +``` |
| 38 | +./configure && make |
| 39 | +``` |
| 40 | + |
| 41 | +如果想编译出arm的二进制,在arm服务器上运行,比如在mac上编译出二进制后放在鲲鹏服务器上跑,也可以用arm docker编译,参考[aarch64](https://github.com/ossrs/dev-docker/tree/aarch64#usage)。 |
| 42 | + |
| 43 | +``` |
| 44 | +docker run -it --rm -v `pwd`:/srs -w /srs ossrs/srs:aarch64 \ |
| 45 | + bash -c "./configure && make" |
| 46 | +``` |
| 47 | + |
| 48 | +对于龙芯和鲲鹏等armv8平台,可能无法识别出来CPU,可以指定为armv8,参考[#1282](https://github.com/ossrs/srs/issues/1282#issuecomment-568891854): |
| 49 | + |
| 50 | +```bash |
| 51 | +./configure --extra-flags='-D__aarch64__' && make |
| 52 | +``` |
| 53 | + |
| 54 | +直接运行SRS: |
| 55 | + |
| 56 | +``` |
| 57 | +./objs/srs -c conf/console.conf |
| 58 | +``` |
| 59 | + |
| 60 | +推流到这个docker: |
| 61 | + |
| 62 | +``` |
| 63 | +ffmpeg -re -i doc/source.flv -c copy -f flv rtmp://127.0.0.1:1935/live/livestream |
| 64 | +``` |
| 65 | + |
| 66 | +播放:[http://localhost:8080/live/livestream.flv](http://localhost:8080/players/srs_player.html?autostart=true&stream=livestream.flv&port=8080&schema=http) |
| 67 | + |
| 68 | + |
| 69 | + |
| 70 | +<a name="ubuntu-cross-build-srs"></a> |
| 71 | + |
| 72 | +## Ubuntu Cross Build SRS: ARMv8(aarch64) |
| 73 | + |
| 74 | +!!! 注意,请先确认是否需要交叉编译,一般可以直接编译,除非极少数情况,参考[#1547](https://github.com/ossrs/srs/issues/1547#issue-543780097)。 |
| 75 | + |
| 76 | +启动容器Ubuntu20(xenial),主目录为SRS: |
| 77 | + |
| 78 | +``` |
| 79 | +cd ~/git/srs/trunk |
| 80 | +docker run --rm -it -v `pwd`:/srs -w /srs \ |
| 81 | + registry.cn-hangzhou.aliyuncs.com/ossrs/srs:ubuntu20 bash |
| 82 | +``` |
| 83 | + |
| 84 | +> 推荐使用阿里云的容器,下载的速度比较快,也可以使用docker官方容器:`ossrs/srs:ubuntu20` |
| 85 | +
|
| 86 | +安装toolchain(容器已经安装好了): |
| 87 | + |
| 88 | +``` |
| 89 | +apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu |
| 90 | +``` |
| 91 | + |
| 92 | +交叉编译SRS: |
| 93 | + |
| 94 | +``` |
| 95 | +./configure --cross-build --cross-prefix=aarch64-linux-gnu- |
| 96 | +make |
| 97 | +``` |
| 98 | + |
| 99 | +> 编译时,默认会重新交叉编译OpenSSL,而不会使用系统的SSL,如果需要强制使用系统的SSL,可以用`--use-sys-ssl`。 |
| 100 | +
|
| 101 | +> 若编译时无法识别出aarch64,可以在configure时加编译选项`--extra-flags='-D__aarch64__'`,一般没有这个问题。 |
| 102 | +
|
| 103 | +在ARMv8(aarch64)的docker上跑SRS:https://hub.docker.com/r/arm64v8/ubuntu |
| 104 | + |
| 105 | +``` |
| 106 | +cd ~/git/srs/trunk && docker run --rm -it -v `pwd`:/srs -w /srs \ |
| 107 | + -p 1935:1935 -p 1985:1985 -p 8080:8080 arm64v8/ubuntu \ |
| 108 | + ./objs/srs -c conf/console.conf |
| 109 | +``` |
| 110 | + |
| 111 | +推流到这个docker: |
| 112 | + |
| 113 | +``` |
| 114 | +ffmpeg -re -i doc/source.flv -c copy -f flv rtmp://127.0.0.1:1935/live/livestream |
| 115 | +``` |
| 116 | + |
| 117 | +播放:[http://localhost:8080/live/livestream.flv](http://localhost:8080/players/srs_player.html?autostart=true&stream=livestream.flv&port=8080&schema=http) |
| 118 | + |
| 119 | +## Ubuntu Cross Build SRS: ARMv7 |
| 120 | + |
| 121 | +!!! 注意,请先确认是否需要交叉编译,一般可以直接编译,除非极少数情况,参考[#1547](https://github.com/ossrs/srs/issues/1547#issue-543780097)。 |
| 122 | + |
| 123 | +启动容器Ubuntu20(xenial),主目录为SRS: |
| 124 | + |
| 125 | +``` |
| 126 | +cd ~/git/srs/trunk |
| 127 | +docker run --rm -it -v `pwd`:/srs -w /srs \ |
| 128 | + registry.cn-hangzhou.aliyuncs.com/ossrs/srs:ubuntu20 bash |
| 129 | +``` |
| 130 | + |
| 131 | +> 推荐使用阿里云的容器,下载的速度比较快,也可以使用docker官方容器:`ossrs/srs:ubuntu20` |
| 132 | +
|
| 133 | +安装toolchain(容器已经安装好了),例如[Acqua or RoadRunner board](https://www.acmesystems.it/arm9_toolchain) |
| 134 | + |
| 135 | +``` |
| 136 | +apt-get install -y gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf |
| 137 | +``` |
| 138 | + |
| 139 | +交叉编译SRS: |
| 140 | + |
| 141 | +``` |
| 142 | +./configure --cross-build --cross-prefix=arm-linux-gnueabihf- |
| 143 | +make |
| 144 | +``` |
| 145 | + |
| 146 | +> 编译时,默认会重新交叉编译OpenSSL,而不会使用系统的SSL,如果需要强制使用系统的SSL,可以用`--use-sys-ssl`。 |
| 147 | +
|
| 148 | +在ARMv7的docker上跑SRS:https://hub.docker.com/r/armv7/armhf-ubuntu |
| 149 | + |
| 150 | +``` |
| 151 | +cd ~/git/srs/trunk && docker run --rm -it -v `pwd`:/srs -w /srs \ |
| 152 | + -p 1935:1935 -p 1985:1985 -p 8080:8080 armv7/armhf-ubuntu \ |
| 153 | + ./objs/srs -c conf/console.conf |
| 154 | +``` |
| 155 | + |
| 156 | +推流到这个docker: |
| 157 | + |
| 158 | +``` |
| 159 | +ffmpeg -re -i doc/source.flv -c copy -f flv rtmp://127.0.0.1:1935/live/livestream |
| 160 | +``` |
| 161 | + |
| 162 | +播放:[http://localhost:8080/live/livestream.flv](http://localhost:8080/players/srs_player.html?autostart=true&stream=livestream.flv&port=8080&schema=http) |
| 163 | + |
| 164 | +## Ubuntu Cross Build SRS: ARMv7(hisiv500) |
| 165 | + |
| 166 | +首先,找一台Ubuntu20的虚拟机,或者启动Docker: |
| 167 | + |
| 168 | +```bash |
| 169 | +docker run --rm -it -v $(pwd):/srs -w /srs/trunk \ |
| 170 | + registry.cn-hangzhou.aliyuncs.com/ossrs/srs:ubuntu20 bash |
| 171 | +``` |
| 172 | + |
| 173 | +宿主机是64位的,而编译工具是32位的,所以需要安装一个工具: |
| 174 | + |
| 175 | +```bash |
| 176 | +apt-get -y install lib32z1-dev |
| 177 | +``` |
| 178 | + |
| 179 | +然后,从[海思](https://www.hisilicon.com/)下载交叉编译工具,或者从网上找地方下载。解压后安装: |
| 180 | + |
| 181 | +```bash |
| 182 | +chmod +x arm-hisiv500-linux.install |
| 183 | +./arm-hisiv500-linux.install |
| 184 | +source /etc/profile |
| 185 | +``` |
| 186 | + |
| 187 | +验证环境, 执行`which arm-hisiv500-linux-g++`能成功找到编译器,就安装成功了: |
| 188 | + |
| 189 | +```bash |
| 190 | +which arm-hisiv500-linux-g++ |
| 191 | +# /opt/hisi-linux/x86-arm/arm-hisiv500-linux/target/bin/arm-hisiv500-linux-g++ |
| 192 | +``` |
| 193 | + |
| 194 | +编译SRS,命令如下: |
| 195 | + |
| 196 | +```bash |
| 197 | +./configure --cross-build --cross-prefix=arm-hisiv500-linux- |
| 198 | +make |
| 199 | +``` |
| 200 | + |
| 201 | +在海思的板子启动SRS就可以了: |
| 202 | + |
| 203 | +```bash |
| 204 | +./objs/srs -c conf/console.conf |
| 205 | +``` |
| 206 | + |
| 207 | +## Use Other Cross build tools |
| 208 | + |
| 209 | +!!! 注意,请先确认是否需要交叉编译,一般可以直接编译,除非极少数情况,参考[#1547](https://github.com/ossrs/srs/issues/1547#issue-543780097)。 |
| 210 | + |
| 211 | +SRS相关的参数如下: |
| 212 | + |
| 213 | +```bash |
| 214 | +./configure -h |
| 215 | + |
| 216 | +Presets: |
| 217 | + --cross-build Enable cross-build, please set bellow Toolchain also. Default: off |
| 218 | + |
| 219 | +Cross Build options: @see https://ossrs.net/lts/zh-cn/docs/v6/doc/arm#ubuntu-cross-build-srs |
| 220 | + --cpu=<CPU> Toolchain: Select the minimum required CPU. For example: --cpu=24kc |
| 221 | + --arch=<ARCH> Toolchain: Select architecture. For example: --arch=aarch64 |
| 222 | + --host=<BUILD> Toolchain: Build programs to run on HOST. For example: --host=aarch64-linux-gnu |
| 223 | + --cross-prefix=<PREFIX> Toolchain: Use PREFIX for tools. For example: --cross-prefix=aarch64-linux-gnu- |
| 224 | + |
| 225 | +Toolchain options: |
| 226 | + --static=on|off Whether add '-static' to link options. Default: off |
| 227 | + --cc=<CC> Toolchain: Use c compiler CC. Default: gcc |
| 228 | + --cxx=<CXX> Toolchain: Use c++ compiler CXX. Default: g++ |
| 229 | + --ar=<AR> Toolchain: Use archive tool AR. Default: g++ |
| 230 | + --ld=<LD> Toolchain: Use linker tool LD. Default: g++ |
| 231 | + --randlib=<RANDLIB> Toolchain: Use randlib tool RANDLIB. Default: g++ |
| 232 | + --extra-flags=<EFLAGS> Set EFLAGS as CFLAGS and CXXFLAGS. Also passed to ST as EXTRA_CFLAGS. |
| 233 | +``` |
| 234 | + |
| 235 | +具体使用例子参考[这里](#ubuntu-cross-build-srs) |
| 236 | + |
| 237 | +**--extra-flags** |
| 238 | + |
| 239 | +之前在支持ARM时,新增过一个Flags的选项( https://github.com/ossrs/srs/issues/1282#issuecomment-568891854 ),会设置`CFLAGS and CXXFLAGS`,也会将这个设置传递到ST设置`EXTRA_CFLAGS`。同样,对于交叉编译,这个选项也是有效的。 |
| 240 | + |
| 241 | +Winlin 2014.2 |
| 242 | + |
| 243 | + |
| 244 | + |
| 245 | + |
0 commit comments