简体   繁体   English

从一个.cpp文件中找到文件,但从另一个.cpp文件中给出“无此文件或目录”

[英]file found from one .cpp file, but give “No such file or directory” from another .cpp file

in CCellBridge.cpp, CCellBridge.h is found 在CCellBridge.cpp中,找到CCellBridge.h
but in main.cpp, CCellBridge.h gives: 但在main.cpp中,CCellBridge.h给出了:

main.cpp:15:25: fatal error: CCellBridge.h: No such file or directory
  #include "CCellBridge.h"

i even copy/paste 我什至复制/粘贴

#include "CCellBridge.h"

from CCellBridge.cpp into main.cpp 从CCellBridge.cpp到main.cpp

in main.cpp, it will see the functions from CCellBridge.h 在main.cpp中,它将看到CCellBridge.h中的功能

i have cleaned/compiled, closed, clean/compiled, but the error still shows. 我已经清理/编译,关闭,清理/编译,但是错误仍然显示。 how can the IDE see the class, but the compiler can not? IDE如何看到该类,但编译器看不到? both files are in same project. 两个文件都在同一个项目中。 i have closed file and opened file in project just to make sure it was the correct file. 我已经关闭文件并在项目中打开文件只是为了确保它是正确的文件。

this is in main, it sees it. 这是主要的,它看到了。 no yellow or red lines under code. 代码下没有黄线或红线。

CCellBridge cellBridge = new CCellBridge();
cellBridge.GetFire();

type 类型

cellBridge.

and list of functions show up 并显示功能列表

yet 然而

#include "CCellBridge.h"

in main.cpp has yellow line under it 在main.cpp下有黄线

guess this needs clarifying: 猜想这需要澄清:
file CCellBridge.cpp 文件CCellBridge.cpp

 //
 #include "CCellBridge.h"

 CCellBridge::CCellBridge()
 {

 }

works 作品

file main.cpp 文件main.cpp

 #include <cstdlib>
 #include "CCellBridge.h"

 using namespace std;

 int main(int argc, char** argv) 
 {
     CCellBridge cellBridge = new CCellBridge();
     return 0;
 }

does not work 不起作用

file main.cpp 文件main.cpp

 #include <cstdlib>
 #include "CCellBridge.h"

 using namespace std;

 int main(int argc, char** argv) 
 {
     CCellBridge cellBridge = new CCellBridge();
     cellBridge.  [note: this give list of function in class CCellBridge]
     return 0;
 }

Did you add the include directories path properly in the Project Settings in your IDE(assuming its Visual Studio). 您是否在IDE的“项目设置”中正确添加了包含目录路径(假设使用Visual Studio)。 Open C/C++ General tab in VS IDE and check against the first entry "Additional Include Directories". 在VS IDE中打开“ C / C ++常规”选项卡,然后检查第一个条目“其他包含目录”。 The directory containing "CCellBridge.h" should be present in this list. 包含“ CCellBridge.h”的目录应出现在此列表中。 Let me know if this helps!! 让我知道这是否有帮助!

i verified that it was NOT in same folder. 我确认它不在同一文件夹中。 had to remove files from project, copy files to project folder, add files to project. 必须从项目中删除文件,将文件复制到项目文件夹,将文件添加到项目。

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

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