[英]How to fix invalid ELF header error, on raspberry pi 3 running on Balena?
I am trying to convert a Node.js application using the rpio library, to run on a Raspberry Pi 3 powered by Balena in local mode.我正在尝试使用rpio库转换 Node.js 应用程序,以在本地模式下在由Balena提供支持的 Raspberry Pi 3 上运行。 In other words, I am looking to control GPIO's on the raspberry pi through Nodejs+Docker+Balena.
换句话说,我希望通过 Nodejs+Docker+Balena 控制树莓派上的 GPIO。
My Dockerfile
installs gcc-4.8 support as mentioned as a dependency by the rpio library.我的
Dockerfile
安装了 gcc-4.8 支持,正如 rpio 库所提到的那样。 The container is build without any problems.容器构建没有任何问题。 But when the node process starts it throws the error invalid ELF header :
但是当节点进程启动时,它会抛出错误invalid ELF header :
17:50:00 - error: uncaughtException: /usr/src/app/node_modules/rpio/build/Release/rpio.node: invalid ELF header
To debug if the error was somehow related to the platform architecture, I added the command RUN uname -a
both in the dockerfile and in the node's application code.为了调试错误是否与平台架构有关,我在 dockerfile 和节点的应用程序代码中添加了命令
RUN uname -a
。 The correspondingly return the following:相应的返回如下:
(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
I have a hard time figuring out what to do from here, since the architecture seems to match.我很难弄清楚从这里做什么,因为架构似乎匹配。
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包.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"
}
Full error stack完整的错误堆栈
[ '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)' ] }
I believe the issue is that the node module needs to be created on the host machine.我认为问题在于需要在主机上创建节点模块。 Because you are running in docker, you need to ignore your outdated node_modules so that the rpio module is created on the fly since it depends on hardware.
因为您在 docker 中运行,所以您需要忽略过时的 node_modules,以便 rpio 模块是动态创建的,因为它依赖于硬件。 All I had to do to fix this is add a.dockerignore with 'node_modules' and it compiled correctly.
要解决此问题,我所要做的就是添加带有“node_modules”的 a.dockerignore 并正确编译。
Not sure how copying package-lock.json affects this.不确定复制 package-lock.json 对此有何影响。
Hope it helps,希望能帮助到你,
If you are running inside a docker container as I am, all you need is a .dockerignore with 'node_modules' specified in it. 如果您像我一样在docker容器中运行,则只需要在其中指定'node_modules'的.dockerignore。
Some libraries need to be compiled on the host machine and therefore your modules can be stale. 一些库需要在主机上编译,因此您的模块可能过时。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.