c++ - Docker/C++ 问题 - 编译错误 /usr/bin/ld: cannot open output file server: Is a directory
问题描述
我正在尝试在 Docker 中容器化的 ubuntu 中使用 cmake 编译 C++ 程序。如果没有 Docker,我可以让它工作得很好,但是有了它,我似乎遇到了一些错误,无论我似乎无法修复它们:/
我试图解决改变许多不同组合的路径,希望我只是写在错误的路径上。
FROM ubuntu:16.04
# Set the working directory to /app
WORKDIR /app
# Copy the current directory contents into the container at /app
COPY . /app
# Install any needed packages specified in the requirements.txt
RUN apt-get update && apt-get -y install g++ make cmake-curses-gui libsqlite3-dev libmariadb-client-lgpl-dev subversion
# Make port 8078 available to the world outside this container
EXPOSE 8078
# Retrieve EOServ and build it
RUN svn checkout svn://eoserv.net/eoserv/trunk/ /app/eoserv
RUN cd /app/eoserv && mkdir build && cd build
RUN cmake -G "Unix Makefiles" /app/eoserv
RUN make
# Run ./eoserv when the container launches
RUN /app/eoserv/eoserv
# Here I've tried several options like
# RUN ./eoserv
# RUN cd /app/eoserv && ./eoserv
预期的结果将是所需文件夹中的 eoserv 二进制文件,当我不在 docker 映像中运行它时,它可以工作,而是在没有 Docker 的情况下自行创建。实际结果是:
[ 91%] Building C object CMakeFiles/eoserv.dir/tu/sha256.c.o
[100%] Linking CXX executable eoserv
/usr/bin/ld: cannot open output file eoserv: Is a directory
collect2: error: ld returned 1 exit status
CMakeFiles/eoserv.dir/build.make:305: recipe for target 'eoserv' failed
make[2]: *** [eoserv] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/eoserv.dir/all' failed
make[1]: *** [CMakeFiles/eoserv.dir/all] Error 2
Makefile:127: recipe for target 'all' failed
make: *** [all] Error 2
The command '/bin/sh -c make' returned a non-zero code: 2
解决方案
该RUN
指令启动一个新的 shell。因此,您RUN
之前的命令将仅是该 shell 的本地命令,其中包括诸如 之类的内容cd
,并且下一RUN
条指令将在不了解前一个的情况下启动一个新的 shell。
说明
RUN cd /app/eoserv && mkdir build && cd build
RUN cmake -G "Unix Makefiles" /app/eoserv
RUN make
需要组合成一条 RUN
指令
RUN cd /app/eoserv && mkdir build && cd build && cmake -G "Unix Makefiles" /app/eoserv && make
您当然可以编写一个运行命令的脚本,并使用RUN
指令调用该脚本。
推荐阅读
- c# - 毫无意义的问题。可以删除
- model - --passes 在 Python VowpalWabbit 中有什么作用?
- lua - Lua/LOVE2D - 尝试索引本地“quad”(一个零值)
- reactjs - 如何清除条纹(React)中成功的所有表单值?
- spring - Spring Boot 是否支持 Managed Executor Services?
- swift - SwiftUI - 如何在 CoreData 中删除实体中的行
- javascript - 在带有 Hooks 的 React 中以两种方式绑定多个输入
- c# - 如何在 Angular 中使用 Dropzone 传递 formData?
- amazon-web-services - 如何处理来自 API 网关的 lambda 错误
- reactjs - 反应子组件仅接收第一个元素作为道具