c++ - Docker/C++ 问题 - 编译错误/usr/bin/ld : cannot open output file server: Is a directory

标签 c++ docker makefile

我正在尝试在 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 镜像中运行它时它会工作,但它本身就是 cmake,没有 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指令启动一个新的外壳。因此,您之前RUN 的命令只会在该 shell 的本地执行,其中包括 cd 之类的内容,而下一个 RUN 指令将启动一个新的外壳不知道以前的。

说明

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++ - Docker/C++ 问题 - 编译错误/usr/bin/ld : cannot open output file server: Is a directory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57865591/

相关文章:

makefile - 如何使创建的包在 make menuconfig 上可用?

c++ - 类模板 : restrict the template parameter

c++ - 这种计算大数的方法是如何工作的?

c++ - 如何将 cv::Mat 转换为 vtkImageData?

docker - 如何在Docker中为WSO2 Identity Server指定SSL证书?

带有 rsync 的 docker-machine

android - 如何在 ndk 应用程序中链接任何库

c++ - C++什么时候适合使用函数模板生成模板函数而不是显式编写函数?

docker - 如何重新创建使用卷的 docker mysql 镜像?

c++ - 来自变量的 Makefile : select files by extension,