C&C++   发布时间:2022-04-03  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了c – 如何编译在docker中使用内核函数的C代码并在容器中使用pci设备?大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_674_4@ 我有@L_644_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 -lhiredis


clean:
    rm executable

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

# dist and build are folders,not phony targets
.PHONY: all package clean

all: dragon.pb.cc dragon_pb2.py package

dragon.pb.cc: dragon.proto
    protoc --cpp_out=. dragon.proto

dragon_pb2.py: dragon.proto
    protoc --python_out=. dragon.proto

package: build

clean:
    rm -f dragon.pb.*
    rm -f dragon_pb*
    rm -rf build
    rm -rf dist
    rm -f MANIFEST

这是我的Dockerfile

FROM ubuntu:14.04

ENV pg_R_636_11845@AJOR 9.3

RUN apt-get update
RUN apt-get install -y git make protobuf-compiler libhiredis-dev POSTGResql-server-dev-${pg_R_636_11845@AJOR}
RUN apt-get install -y g++
RUN apt-get install -y libzmq-dev
RUN apt-get install -y libprotobuf-dev
RUN apt-get install -y linux-headers-$(uname -r)
ADD deployment_key /root/.ssh/id_rsa
RUN chmod 600 /root/.ssh/id_rsa


RUN echo "StrictHostKeychecking no" >> /root/.ssh/config
RUN echo >> /root/.ssh/config
RUN echo "Host bitbucket.org" >> /root/.ssh/config


RUN mkdir -p /usr/src/app/

WORKDIR /usr/src/app/
RUN git clone git@bitbucket.org:opticsdevelopment/dragon-protocols.git
WORKDIR ./dragon-protocols
RUN make dragon.pb.cc
RUN cp ./dragon.pb.* ../
COPY . /usr/src/app
WORKDIR ../
RUN git clone git@bitbucket.org:opticsdevelopment/dragon-module.git
WORKDIR ./dragon-module
RUN make all
WORKDIR ../
RUN make
EXPOSE 5570
CMD ["dragon"]

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

E: Unable to locate package linux-headers-3.13.0-19-generic
E: 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设备?所遇到的程序开发问题。

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。