如何为 Unix 创建生成文件
How to create a makefile for Unix
好的,我一直收到以下错误消息:
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.o 和 yesno.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
相关文章:
- 终端不会为C++文件创建.exe文件吗
- 如何从具有两列的.txt文件创建并行数组?
- 从 .lib 文件创建一个.dll文件
- 如何从输入文件 c++ 创建随机名称生成器
- 无法从 cso 文件创建顶点着色器(从 fx 文件创建)
- 如何为多个目录中的多个文件创建生成文件?
- 在编译时从 c++ 文件创建枚举
- 如何在运行时从 c++ 中的 DLL 文件创建对象?
- 文件创建并不总是成功
- 如何使用 QFile、c++ 从文件创建整数数组
- 您可以使用 makefile 从 .o 对象文件创建 C++ 文件吗?
- 从函数中的dat文件创建一个2维数组
- 如何为 cpp 和 h 文件创建别名(并忽略编译器__attributes__)
- 如何从现有的生成文件创建 CMake 文件?
- 为什么我无法使用文本文件创建文件映射?
- 通过读取文件创建映射<字符串,矢量>时如何管理内存<string>
- 从文本文件创建 2D 字符串矢量
- ofStream: - 尽管文件创建了,但文本文件上没有输出
- 从语言文件创建JSON对象
- 将文本文件创建到节点.js的插件C++