Docker / C ++问题-编译错误/ usr / bin / ld:无法打开输出文件服务器:是目录

时间:2019-09-10 07:02:35

标签: c++ docker makefile

我正在尝试在Docker容器化的ubuntu中使用cmake编译C ++程序。没有Docker,我可以使其正常工作,但是有了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

1 个答案:

答案 0 :(得分:2)

RUN指令启动一个新的shell。因此,您RUN之前的命令仅在该Shell本地,其中包括诸如cd之类的命令,下一条RUN指令将在不了解前一个Shell的情况下启动新的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指令调用该脚本。

相关问题