如何为 Unix 创建生成文件

How to create a makefile for Unix

本文关键字:文件 创建 Unix      更新时间:2023-10-16

好的,我一直收到以下错误消息:

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 << "nnI demand a rematch!" << endl;
               } 
        }

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

生成文件

这对我来说看起来不错。不过有几个问题。

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

错误不言自明。

您的包含防护尝试测试无效的宏名称,yesno.h 。它应该是yesno_h,以匹配以下定义。

您的标头尝试包含自身,但作为系统标头。它不应该那样做。

你想要更多类似的东西

#ifndef yesno_h
#define yesno_h
// Return true if response is "yes", "y", or any upper/lowercase
// variant of those two strings.
bool yesNo (std::string response);
#endif