我创建了一个包含多个源文件和头文件的C++项目。该程序在代码块中编译和运行良好,但我不能在终端中编译它。
所有文件都在同一个文件夹中。
下面是我输入的命令:
clang++ -std=c++11 main.cpp file1.cpp file1.h 它显示:
clang: warning: treating 'c-header' input as 'c++-header' when in C++ mode, this behavior is deprecated以及大量的错误:
error: use of undeclared identifier 'std' 在头文件里。
发布于 2016-09-28 18:27:08
您应该避免编译头文件(.h)。
试着:
clang++ -std=c++11 main.cpp file1.cpp头文件是预处理程序将包含在需要它的cpp文件中的东西(那些使用#include预处理器指令的编译单元)。
发布于 2016-09-28 18:27:52
您不应该只编译源文件,而不应该编译头文件。在需要引用头文件的源文件中,将#include "file1.h"放在顶部。
https://stackoverflow.com/questions/39755010
复制相似问题