我正在尝试使用Docker和CMake构建我的C项目。使用cmake . && cmake --build .
进行CMake在我的系统(MacOS)上可以正常工作,使用以下CMakeLists.txt:
cmake_minimum_required (VERSION 3.0)
project (PROJECTNAME)
# Include libsodium
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/modules")
find_package(sodium REQUIRED)
include_directories(include)
file(GLOB SOURCES "src/*.c")
set(LIBRARY_OUTPUT_PATH "build")
add_library(project STATIC ${SOURCES})
target_link_libraries(project sodium)
find_package(sodium REQUIRED)
所需的Findsodium.cmake是the libsodium GitHub上文件的直接副本。
现在,我正在尝试使用docker build
和以下Dockerfile来构建它(我知道它安装的某些软件包是多余的):
FROM ubuntu:16.04
COPY . /project
RUN apt-get update && apt-get -y install \
build-essential \
cmake \
libsodium18 \
curl
RUN cd project && cmake .
RUN cmake --build .
不幸的是,这失败并显示以下消息:
CMake Error at /usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Could NOT find sodium (missing: sodium_LIBRARY_RELEASE sodium_LIBRARY_DEBUG
sodium_INCLUDE_DIR)
Call Stack (most recent call first):
/usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
cmake/modules/Findsodium.cmake:226 (find_package_handle_standard_args)
CMakeLists.txt:8 (find_package)
当我运行普通的docker容器并手动执行步骤时,会引发相同的错误。即使已正确安装,也无法找到libsodium:
$ ldconfig -p | grep sodium
libsodium.so.18 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libsodium.so.18
任何在Ubuntu或其他操作系统上使用 Findsodium.cmake 有经验的人都可以提供一些见识?
编辑:根据LinPy的建议,我添加了libsodium-dev
作为要安装的软件包,并且错误略有改变:
CMake Error at /usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Could NOT find sodium (missing: sodium_LIBRARY_RELEASE
sodium_LIBRARY_DEBUG) (found version "
#ifndef sodium_version_H
#define sodium_version_H
#include "export.h"
#define SODIUM_VERSION_STRING "1.0.8"
...
...
")
Call Stack (most recent call first):
/usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
cmake/modules/Findsodium.cmake:226 (find_package_handle_standard_args)
CMakeLists.txt:8 (find_package)
似乎现在可以找到一些东西,但是找不到调试和发布库吗?
Dockerfile现在看起来像这样:
FROM ubuntu:16.04
COPY . /project
RUN apt-get update && apt-get -y install \
build-essential \
cmake \
libsodium18 \ # also tried it without this line
libsodium-dev \
curl
RUN cd project && cmake .
RUN cmake --build .
编辑2 :添加pkg-config
也可以解决第二个错误。
答案 0 :(得分:2)
将此添加到您的dockerfile
:
RUN apt-get install -y libsodium-dev pkg-config