C++中头文件的结构,并通过终端Mac进行编译
structure of header files in C++ and compiling via Terminal Mac
我对头文件的结构感到困惑。在我的程序中,头文件只有一个int add(int x, int y);
的正向声明,在main方法中,它调用头文件,但不使用任何返回语句初始化正向声明,它只分配x和y的特定值。换句话说,当头文件中的代码没有任何返回类型时,main方法如何知道该如何处理头文件内的代码。任何帮助都将不胜感激。如果有帮助的话,下面是两个文件的代码:
add.h:
int add(int x, int y); // function prototype for add.h
main.cpp:
#include <iostream>
#include "add.h" // this brings in the declaration for add()
int main()
{
using namespace std;
cout << "The sum of 3 and 4 is " << add(3, 4) << endl;
return 0;
}
我使用g++ add.h main.cpp execution1; ./execution1
从终端编译它,得到了这个错误:
clang: warning: treating 'c-header' input as 'c++-header' when in C++ mode, this behavior is deprecated
clang: error: cannot specify -o when generating multiple output files
-bash: ./execution1: No such file or directory
这是重复的,请参阅此处:如何在Mac 上通过命令行编译C++程序
但你回答。。。
您可以使用c++ -c main.cpp
,然后使用c++ main.o
,它将生成.exe
。
再见!
相关文章:
- 如何在linux终端中同时编译和运行c++代码
- Mac os x app bundle 在下载并运行时崩溃,但在终端或更改 Info.plist 时运行良好
- 在终端中运行可执行文件与在Mac查找器中打开
- 使用 Mac 终端编译器编译 c++14 代码
- 从Mac上的终端编译时C 错误
- 如何在Mac终端中编译C ++程序
- 如何在Mac终端中查看C++功能的损坏名称
- 无法在Mac终端中运行qmake
- clang编译器在终端Mac OSX上不起作用
- 无法使用 Xcode 和终端在 Mac OS 上使用 OpenGL 库编译 c++ 文件
- C++中头文件的结构,并通过终端Mac进行编译
- 如何通过终端Mac编译C++程序
- C++程序需要很长时间才能在Mac OSX终端上编译
- 在Mac终端上编译OpenGL程序
- 使-std=c++11成为mac终端中的默认值
- Mac:服务器上的终端编译器错误
- 如何在mac osx中隐藏终端窗口
- C++ Mac 终端中不显示 Unicode
- 如何在MAC OS 10上使用终端编写和编译c++代码
- 如何在Mac终端上编译支持c++ 11的c++