简体   繁体   English

如何为Unix创建Makefile

[英]How to create a makefile for Unix

Ok I keep receiving the following error message: 好吧,我继续收到以下错误消息:

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

It is referring to the last part of my code which is: 它指的是我代码的最后一部分:

 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;
               } 
        }

I have deleted the } and added it back and I still continue to get the same error message. 我已删除}并将其添加回去,但我仍然继续收到相同的错误消息。 What am I doing wrong? 我究竟做错了什么?

MAKEFILE MAKEFILE

This looks good to me. 这对我来说很好。 There are a couple of issues though. 虽然有两个问题。

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

g++ needs the -o option to name the output file. g++需要使用-o选项来命名输出文件。 It's the same syntax as if you'd run it in the command line. 语法与在命令行中运行时的语法相同。 And I'd put a space after the colon. 我会在冒号后面放一个空格。 But I'm not sure if that's mandatory. 但是我不确定这是否是强制性的。

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

guess.o and yesno.o also need the dependency with their respective cpp files. guess.oyesno.o也需要依赖于它们各自的cpp文件。

Like this: 像这样:

guess.o: guess.cpp yesno.h

The errors speak for themselves. 错误说明一切。

Your include guard tries to test an invalid macro name, yesno.h . 您的包含后卫会尝试测试无效的宏名称yesno.h It should be yesno_h , to match the following definition. 它应该是yesno_h ,以匹配以下定义。

Your header tries to include itself, but as a system header. 您的标头尝试包括自身,但作为系统标头。 It shouldn't do that. 它不应该那样做。

You want something more like 您想要更多类似的东西

#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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM