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

标签 c++ gcc makefile linux-kernel docker

我有一个 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 库。这个库的 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_MAJOR 9.3

RUN apt-get update
RUN 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-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 header 进行编译

在您的 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 容器运行命令上,链接该卷,如

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

关于c++ - 如何编译在docker中使用内核函数的C代码并在容器中使用pci设备?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31520742/

相关文章:

c++ - 将 QImage 分成更小的部分

c++ - Linux gcc 4.9 wstring 未定义

用于编译源文件列表的 Makefile

compilation - 使 : $LD_RUN_PATH is ignored

gcc - 链接器输入文件未使用,因为链接未完成 - gcc

c++ - 尝试将文本文件加载到链表时出现多个转换错误

c++ - 高效地围绕 QPainterPath 绘制文本

c - 我有以下 gcc 编译警告

c++ - Qt 窗口关闭时如何释放内存?

c - gcc gdb building - "lvalue required as increment operand"on *((void **)__o->next_free)++ = ((void *)datum);