【问题标题】:attempting to get main.cpp output using the makefile command make尝试使用 makefile 命令获取 main.cpp 输出
【发布时间】:2021-09-02 23:33:12
【问题描述】:

g++: 错误: main: 没有这样的文件或目录 g++:致命错误:没有输入文件 编译终止。 make: *** [Makefile:2: main] 错误 1

这是我的制作文件

主要:main.cpp g++ main -o main.cpp

main.o: g++ -c main.cpp 虚假:干净 干净的: rm * .o main.cpp

【问题讨论】:

  • 请使用 StackOverflow 的格式化工具编辑您的问题,以便我们可以准确地查看您的 makefile。

标签: makefile


【解决方案1】:

这不是生成文件问题。这是因为您需要学习如何调用您的编译器以及它需要哪些选项。您可以在此处找到有关如何调用 GCC 的文档:https://gcc.gnu.org/onlinedocs/gcc-11.2.0/gcc/Invoking-GCC.html#Invoking-GCC

像 GCC 这样的编译器会将其输出写入由-o 选项指定的文件。选项的工作方式是首先提供选项,然后提供选项的参数。你不能把命令行上的所有选项都按随机顺序混在一起。

你有:

g++ main -o main.cpp

通过将main.cpp 放在-o 选项之后,您是在告诉GCC 输出 文件应该命名为main.cpp,这显然是不对的。

你希望你的编译行是这样的:

g++ -o main main.cpp

由于您在此处编译源文件,因此其他规则(构建main.o)是无用的。

另外你想把main.cpp列为main的先决条件,否则当main.cpp被修改时make不会知道它需要重新创建main

main: main.cpp
        gcc -o main main.cpp

【讨论】:

    猜你喜欢
    • 2020-03-22
    • 2013-04-25
    • 2012-10-27
    • 2016-09-07
    • 1970-01-01
    • 1970-01-01
    • 2013-02-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多