cmake can’t find_package in docker image

  cmake, docker, gcc, openssl

I encountered a problem with cmake in docker, where cmake failed to find OpenSSL package in the system, but I’m sure it’s installed. And I see strange errors about required internal CMake variable not set.

enter image description here

I can compile the same code in normal VM without a problem, but I cannot get it to work in docker.

Does anyone know what’s wrong here?
I’ve uploaded the full code in:
https://gitlab.com/kenjichanhkg/docker_cmake_hello_world.git
Please check out the "cmake_helloworld" branch.

The dockerfile looks like this:

FROM gcc:latest
COPY . /usr/test/src
WORKDIR /usr/test/src

RUN apt update -y && apt install -y 
    cmake 
    libssl-dev 
    git

RUN ./build.sh

CMD [ "./build/test" ]

the cmake file looks like this:

cmake_minimum_required( VERSION 3.13 )

find_package(OpenSSL REQUIRED)
project( docker_cmake_hello_world )

add_executable(test main.cpp)

include_directories(  
        ${OPENSSL_INCLUDE_DIR}
)

target_link_libraries(
        test
        OpenSSL::SSL
)

Thanks!!

Source: Docker Questions

LEAVE A COMMENT