I have a Dockerfile that has two stages, one is a build stage that compiles C++ projects and then in the second stage I am copying the binaries over into a python image.
This all seems to work fine but the problem is that during the cmake process, pybind11 is used to create a Python wrapper for this c++ tool. I need that Python wrapper to work in my python image, but i'm not sure how to make that happen.
When I try to run my python code on container startup, which imports from the pybind11 linked .cpp code, it gives an error saying that it cannot find the package.
My docker file looks like this:
FROM ubuntu:latest as builder
RUN apt-get update && apt-get install -yq \
make \
g++ \
gcc
RUN #script that uses cmake to build tool
FROM python:3.9
COPY --from=builder /app/tool /app/tool
CMD [#runs a python project that imports the pybind11 linked tool]
In the cmake it does this at the end:
add_subdirectory(../pybind11 pybind11)
pybind11_add_module(tool tool/tool.cpp)
target_link_libraries(tool PRIVATE toollib)
Is there a way to replicate this linking in my final build stage? I haven't ever used cmake or pybind11.
Will I have to just do the cmake build in my final stage?
For reference, this works when I do everything in one build stage but the resulting container is huge.