本文介绍了如果#include无法找到文件会发生什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有这个非常基本的c ++代码:

Say I have this very basic c++ code:

myCode.cpp:

myCode.cpp:

#include <library1.h>
#include <library2.h>

int main() {
 // use some methods from library2
}

如果编译此代码但我的编译器找不到library1.h会发生什么?它会抛出任何特定错误吗?它还在寻找library2.h吗?它会跳过其余的#include语句并继续编译main吗?我问,因为我正在尝试回答添加一个.h文件导致编译器抱怨没有从另一个.h文件中查找方法。如果没有#include第一行.h行,代码就会正确编译。

What will happen if I compile this code but my compiler can't find library1.h? Will it throw any specific error? Will it still look for library2.h? Will it skip the rest of the #include statements and go on to compiling main? I'm asking because I'm trying to answer this SO question where adding one .h file is causing the compiler to complain about not finding methods from another .h file . Without the #include first .h line, the code compiles correctly.

推荐答案

当编译器遇到包含错误时,它会报告它并且停止编译。当然可能的情况是并非所有编译器都会报告一个人为友好的错误,但是肯定他们都会终止,因为这个错误是致命的,因为syam在他的评论中指出了这一点。

When the compiler reaches an include error it reports it and stops the compilation. Of course it may be the case that not all compilers will report a human friendly error, but for sure they all will terminate as this error is fatal as syam points out in his comment.

这篇关于如果#include无法找到文件会发生什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 20:27