c++ - 如何为 Unix 创建 makefile

标签 c++ unix makefile

好的,我不断收到以下错误消息:

g++    -c -o guess.o guess.cpp
guess.cpp: In function ‘int main()’:
guess.cpp:70:7: error: expected ‘}’ at end of input
   }
   ^
guess.cpp:70:7: error: expected ‘}’ at end of input
guess.cpp:70:7: error: expected ‘}’ at end of input
make: *** [guess.o] Error 1

它指的是我代码的最后一部分:

 cout << "Think of an integer between 1 and 1000. I will try to guess it." << endl;

  bool result = doGuesses(0, 1001);
      {
  if (!result) 
               {
    cout << " and is between 1 and 1000." << endl;
    cout << "\n\nI demand a rematch!" << endl;
               } 
        }

我已经删除了 } 并将其添加回来,但我仍然继续收到相同的错误消息。我做错了什么?

最佳答案

MAKEFILE

这对我来说很好。但是有几个问题。

guess:yesno.o guess.o
    g++ guess yesno.o guess.o

g++ 需要 -o 选项来命名输出文件。它的语法与您在命令行中运行它时的语法相同。我会在冒号后面放一个空格。但我不确定这是否是强制性的。

guess.o: yesno.h
yesno.o: yesno.h

guess.oyesno.o 也需要它们各自的 cpp 文件的依赖关系。

像这样:

guess.o: guess.cpp yesno.h

关于c++ - 如何为 Unix 创建 makefile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29907704/

相关文章:

c++ - 从 Fortran 调用 C++(链接问题?)

makefile - 抑制 make 规则错误输出

android - 在 Android Studio 中找不到 opencv2

c++ - 在 C++ 中获取有符号整数乘法的高部分

c++ - 如何为返回数组引用的方法使用 cv 限定符?

linux - 打印一行,其中一个数字在第三个字段中重复了 n 次

linux - Linux bash 脚本中的 Perl 脚本

c++ - 在字符串到 int 转换中使用 atoi 时出错

java - 使用不同的包编译java项目

无法将内核的原型(prototype)放在 header 中