Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Docker/CMake项目中包括外部库_Docker_Cmake - Fatal编程技术网

在Docker/CMake项目中包括外部库

在Docker/CMake项目中包括外部库,docker,cmake,Docker,Cmake,我正在使用docker和cmake构建一个cxx项目,现在我的任务是集成我在本地拥有的第三方库 为了开始,我添加了一个项目,其中只包含一个src文件夹和一个cpp文件,其中包含一个main函数以及我将需要从上述库中获取的内容。此时,我已经陷入困境,因为在docker环境中构建时找不到包含的文件。当我在项目上调用没有docker的cmake时,我不会得到include错误 我的目录树: my_new_project CMakeLists.txt src my_new

我正在使用docker和cmake构建一个cxx项目,现在我的任务是集成我在本地拥有的第三方库

为了开始,我添加了一个项目,其中只包含一个src文件夹和一个cpp文件,其中包含一个main函数以及我将需要从上述库中获取的内容。此时,我已经陷入困境,因为在docker环境中构建时找不到包含的文件。当我在项目上调用没有docker的cmake时,我不会得到include错误

我的目录树:

my_new_project
    CMakeLists.txt
    src
        my_new_project.cpp
CMakeLists.txt
中,我有以下内容:

CMAKE_MINIMUM_REQUIRED (VERSION 3.6)

project(my_new_project CXX)
file(GLOB SRC_FILES src/*.cpp)
add_executable(${PROJECT_NAME} ${SRC_FILES})

include_directories(/home/me/third_party_lib/include)
在Docker环境中进行此构建需要什么?我是否需要将第三方库转换为另一个项目并将其添加为依赖项(类似于我对GitHub中的项目所做的操作)

如果有人能给我指出正确的方向,我会很高兴的

编辑:


我已经复制了整个第三方项目根目录,现在可以使用
include\u目录(/work/third\u party\u lib/include)
,获得add include目录,但这就是方法吗?

当您构建一个新的停靠应用程序时,您需要
复制/添加所有src,在
Dockerfile
中生成和制作文件并定义
运行
指令。这将用于构建docker
图像
,以捕获所有必要的二进制文件、资源、依赖项等。。构建映像后,您可以在docker上从该映像运行容器,它可以为您的应用程序公开端口、绑定卷、设备等

因此,基本上,创建您的
Dockerfile

# Get the GCC preinstalled image from Docker Hub
FROM gcc:4.9

# Copy the source files under /usr/src
COPY ./src/my_new_project /usr/src/my_new_project

# Copy any other extra libraries or dependencies from your machine into the image
COPY /home/me/third_party_lib/include /src/third_party_lib/include

# Specify the working directory in the image
WORKDIR /usr/src/

# Run your cmake instruction you would run
RUN cmake -DKRISLIBRARY_INCLUDE_DIR=/usr/src/third_party_lib/include -DKRISLIBRARY_LIBRARY=/usr/src/third_party_lib/include ./ && \
make && \
make install

# OR Use GCC to compile the my_new_project source file
# RUN g++ -o my_new_project my_new_project.cpp

# Run the program output from the previous step
CMD ["./my_new_project"]
然后可以进行
docker构建-t my_new_project
,然后
docker运行my_new_project
进行尝试

此外,关于将C**应用程序构建为docker容器的例子也很少:

  • VS代码教程:
  • GCC图像和示例:
有关此操作的更多信息,请参阅docker文档:


当您构建一个新的Docked应用程序时,您需要
复制/添加所有src、build和cmake文件,并在
Dockerfile
中定义
运行
指令。这将用于构建docker
图像
,以捕获所有必要的二进制文件、资源、依赖项等。。构建映像后,您可以在docker上从该映像运行容器,它可以为您的应用程序公开端口、绑定卷、设备等

因此,基本上,创建您的
Dockerfile

# Get the GCC preinstalled image from Docker Hub
FROM gcc:4.9

# Copy the source files under /usr/src
COPY ./src/my_new_project /usr/src/my_new_project

# Copy any other extra libraries or dependencies from your machine into the image
COPY /home/me/third_party_lib/include /src/third_party_lib/include

# Specify the working directory in the image
WORKDIR /usr/src/

# Run your cmake instruction you would run
RUN cmake -DKRISLIBRARY_INCLUDE_DIR=/usr/src/third_party_lib/include -DKRISLIBRARY_LIBRARY=/usr/src/third_party_lib/include ./ && \
make && \
make install

# OR Use GCC to compile the my_new_project source file
# RUN g++ -o my_new_project my_new_project.cpp

# Run the program output from the previous step
CMD ["./my_new_project"]
然后可以进行
docker构建-t my_new_project
,然后
docker运行my_new_project
进行尝试

此外,关于将C**应用程序构建为docker容器的例子也很少:

  • VS代码教程:
  • GCC图像和示例:
有关此操作的更多信息,请参阅docker文档: