如何在Balena上运行的raspberry pi 3上修复无效的ELF标头错误?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在Balena上运行的raspberry pi 3上修复无效的ELF标头错误?相关的知识,希望对你有一定的参考价值。
我正在尝试使用rpio库转换Node.js应用程序,使其在本地模式下由Balena驱动的Raspberry Pi 3上运行。换句话说,我希望通过Nodejs + Docker + Balena来控制树莓派上的GPIO。
我的Dockerfile
安装了rpio库作为依赖项提到的gcc-4.8支持。容器的构建没有任何问题。但是,当节点进程启动时,它将引发错误无效的ELF标头:
17:50:00 - error: uncaughtException: /usr/src/app/node_modules/rpio/build/Release/rpio.node: invalid ELF header
为了调试错误是否与平台架构有关,我在dockerfile和节点的应用程序代码中都添加了命令RUN uname -a
。相应地返回以下内容:
(Dockerfile)Linux 96cbf2e6ef3d 4.14.68 #1 SMP Tue Nov 27 09:53:28 UTC 2018 armv7l GNU/Linux
(Node file) Linux 2cfca32 4.14.68 #1 SMP Tue Nov 27 09:53:28 UTC 2018 armv7l GNU/Linux
由于架构似乎匹配,我很难从这里弄清楚该怎么做。
Dockerfile
FROM resin/raspberrypi3-node:8
# use apt-get if you need to install dependencies,
# for instance if you need ALSA sound utils, just uncomment the lines below.
RUN apt-get update && apt-get install -yq \
alsa-utils libasound2-dev gcc-4.8 g++-4.8 && \
apt-get clean && rm -rf /var/lib/apt/lists/*
RUN update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 50 && \
update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 50
RUN gcc --version
# Defines our working directory in container
WORKDIR /usr/src/app
# Copies the package.json first for better cache on later pushes
COPY package.json package.json
# COPY package-lock.json package-lock.json
# This install npm dependencies on the balena build server,
# making sure to clean up the artifacts it creates in order to reduce the image size.
RUN JOBS=MAX npm install --production --unsafe-perm && rm -rf /tmp/*
RUN uname -a
# This will copy all files in our root to the working directory in the container
COPY . ./
# Enable systemd init system in container
ENV INITSYSTEM on
# server.js will run when container starts up on the device
CMD ["npm", "start"]
package.json
"scripts":
"test": "echo \"Error: no test specified\" && exit 1",
"setup-log": "touch logs/app.log",
"prestart": "bash ./deps.sh",
"start": "npm run -s setup-log && node skaale/index.js"
,
"dependencies":
"cron": "^1.2.1",
"firebase-admin": "^6.4.0",
"moment": "^2.18.1",
"request": "^2.88.0",
"request-promise": "^4.2.0",
"rimraf": "^2.6.2",
"rpio": "^1.0.11",
"winston": "^2.3.1",
"winston-daily-rotate-file": "^1.4.6"
完整错误堆栈
[ 'Error: /usr/src/app/node_modules/rpio/build/Release/rpio.node: invalid ELF header',
' at Object.Module._extensions..node (module.js:681:18)',
' at Module.load (module.js:565:32)',
' at tryModuleLoad (module.js:505:12)',
' at Function.Module._load (module.js:497:3)',
' at Module.require (module.js:596:17)',
' at require (internal/module.js:11:18)',
' at bindings (/usr/src/app/node_modules/bindings/bindings.js:81:44)',
' at Object.<anonymous> (/usr/src/app/node_modules/rpio/lib/rpio.js:17:34)',
' at Module._compile (module.js:652:30)',
' at Object.Module._extensions..js (module.js:663:10)',
' at Module.load (module.js:565:32)',
' at tryModuleLoad (module.js:505:12)',
' at Function.Module._load (module.js:497:3)',
' at Module.require (module.js:596:17)',
' at require (internal/module.js:11:18)',
' at Object.<anonymous> (/usr/src/app/utils/gpioHelper.js:5:12)',
' at Module._compile (module.js:652:30)',
' at Object.Module._extensions..js (module.js:663:10)',
' at Module.load (module.js:565:32)',
' at tryModuleLoad (module.js:505:12)',
' at Function.Module._load (module.js:497:3)',
' at Module.require (module.js:596:17)' ]
答案
如果您像我一样在docker容器中运行,则只需要在其中指定'node_modules'的.dockerignore。
某些库需要在主机上编译,因此您的模块可能陈旧。
以上是关于如何在Balena上运行的raspberry pi 3上修复无效的ELF标头错误?的主要内容,如果未能解决你的问题,请参考以下文章
如何配置 NetBeans 11.1 项目以在 Raspberry Pi 上远程运行
如何在运行 Debian Squeeze 和 LXDE 的 Raspberry Pi 上截屏? [关闭]
如何将运行时框架“Microsoft.WindowsDesktop.App”,版本 6.0.0 下载到 Raspberry PI 3b+