c++ - 如何修复这个简单的 Makefile 错误?

标签 c++ shell makefile

我正在尝试创建一个非常简单的 makefile,它将构建我的 C++ 代码以及创建一个 .txt 文件

我希望将可执行文件和 .txt 文件放在名为“build”的目录中。为此,我需要确保构建目录不存在。我遇到了语法错误,而且我似乎无法修复它。这可能是一个非常明显的错误,因为我是创建 makefile 的新手。

有人能帮忙吗?

错误:

/bin/sh: -c: 第 1 行:语法错误:意外的文件结尾 make: *** [mlib] 错误 2

生成文件:

all:
    if [ ! -d build ]; then
        mkdir build
    fi
    g++ src/*.cpp -o build/mlb
    touch build/mlib_history.txt

最佳答案

我实际上通过简单地将 makefile 更改为来修复它:

全部:

if [ ! -d build ]; then mkdir build; fi
#"mkdir build" moved onto the above line
#somehow this fixed it...?
g++ src/*.cpp -o build/mlb
touch build/mlib_history.txt

关于c++ - 如何修复这个简单的 Makefile 错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32388764/

相关文章:

shell - 如何在powershell中运行cygwin脚本

visual-studio - Visual Studio Makefile 项目生成无关的 'obj' 文件夹

c - YACC 和 Lex 未定义对 `yylex' 的引用

c++ - 如何在 C++ 模板中使用比较表达式?

c++ - 将从数据库读取的数据写入二进制文件

iOS:向 IP 地址发出 shell 命令

android - 如果 adb logcat 上的条件不起作用

linux - := and += in make file?有什么区别

c++ - 这些 header 详细信息是否写入正确?

c++ - 在 layer_factory.hpp 创建层错误