Reputation: 983
I'm trying to build my C project using Docker and CMake. CMake'ing using cmake . && cmake --build .
works fine on my system (MacOS), using the following 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)
The Findsodium.cmake, required by find_package(sodium REQUIRED)
is a direct copy of the file on the libsodium GitHub.
Now I'm trying to build this using docker build
and the following Dockerfile (I know some packages it installs are redundant):
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 .
Unfortunately this fails with the following message:
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)
When I run a normal docker container and perform the steps manually the same error is thrown. Somehow libsodium can not be located, even though it is properly installed:
$ ldconfig -p | grep sodium
libsodium.so.18 (libc6,x86-64) => /usr/lib/x86_64-linux-gnu/libsodium.so.18
Anyone with experience using Findsodium.cmake on Ubuntu, or other, that can give some insight?
EDIT: after the suggestion of LinPy I added libsodium-dev
as a package to be installed and the error changes slightly:
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)
It seems that some things could be found now, but not the debug and release library?
Dockerfile looks like this now:
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 .
EDIT 2: Adding pkg-config
as well fixes the second error.
Upvotes: 4
Views: 3283
Reputation: 18608
add this to your dockerfile
:
RUN apt-get install -y libsodium-dev pkg-config
Upvotes: 5