c – 如何编译在docker中使用内核函数的C代码并在容器中使用pci设备?

c – 如何编译在docker中使用内核函数的C代码并在容器中使用pci设备?,第1张

概述我有一个Makefile,一些使用PCI设备的C代码 all: g++ -o executable main.cpp dragon.pb.cc -std=c++11 -O3 -I/usr/include/postgresql -I/usr/include/hiredis -lzmq -lprotobuf -lpthread -lpq -lhiredisclean: rm ex 我有一个Makefile,一些使用PCI设备的C代码

all:    g++ -o executable main.cpp dragon.pb.cc -std=c++11 -O3 -I/usr/include/postgresql -I/usr/include/hiredis -lzmq -lprotobuf -lpthread -lpq -lhiredisclean:    rm executable

它依赖于使用内核函数的C库.这个libraby的Makefile是

# dist and build are folders,not phony targets.PHONY: all package cleanall: dragon.pb.cc dragon_pb2.py packagedragon.pb.cc: dragon.proto    protoc --cpp_out=. dragon.protodragon_pb2.py: dragon.proto    protoc --python_out=. dragon.protopackage: buildclean:    rm -f dragon.pb.*    rm -f dragon_pb*    rm -rf build    rm -rf dist    rm -f MANIFEST

这是我的Dockerfile

FROM ubuntu:14.04ENV PG_MAJOR 9.3RUN apt-get updateRUN apt-get install -y git make protobuf-compiler libhiredis-dev postgresql-server-dev-${PG_MAJOR}RUN apt-get install -y g++RUN apt-get install -y libzmq-devRUN apt-get install -y libprotobuf-devRUN apt-get install -y linux-headers-$(uname -r)ADD deployment_key /root/.ssh/ID_rsaRUN chmod 600 /root/.ssh/ID_rsaRUN echo "StrictHostKeyChecking no" >> /root/.ssh/configRUN echo >> /root/.ssh/configRUN echo "Host bitbucket.org" >> /root/.ssh/configRUN mkdir -p /usr/src/app/workdir /usr/src/app/RUN git clone [email protected]:opticsdevelopment/dragon-protocols.gitworkdir ./dragon-protocolsRUN make dragon.pb.ccRUN cp ./dragon.pb.* ../copY . /usr/src/appworkdir ../RUN git clone [email protected]:opticsdevelopment/dragon-module.gitworkdir ./dragon-moduleRUN make allworkdir ../RUN makeEXPOSE 5570CMD ["dragon"]

现在的问题是安装linux-headers.不知怎的,它找不到标题

E: Unable to locate package linux-headers-3.13.0-19-genericE: Couldn't find any package by regex 'linux-headers-3.13.0-19-generic'
解决方法 如果你的应用程序可以使用任何通用linux头编译

在Dockerfile中更改

RUN apt-get install -y linux-headers-$(uname -r)

只是

RUN apt-get install -y linux-headers-generic

或者如果您需要与主机系统相同的特定一个
你为什么不用这个目录将这个目录从主机链接到带有-v的docker容器

在您的主机系统上:

sudo apt-get install linux-headers-$(uname -r)

现在你有了内核头文件:/usr/src / linux-headers – $(uname -r)/ include

现在在您的docker container run命令中,链接该卷就像

-v /usr/src/linux-headers-$(uname -r)/include:/usr/src/linux-headers-$(uname -r)/include
总结

以上是内存溢出为你收集整理的c – 如何编译在docker中使用内核函数的C代码并在容器中使用pci设备?全部内容,希望文章能够帮你解决c – 如何编译在docker中使用内核函数的C代码并在容器中使用pci设备?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1227803.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存