简体   繁体   English

找不到包含文件

[英]Cannot find include file

I have a solution with 2 projects in it: 我有一个包含2个项目的解决方案:

  • ControlGUI ControlGUI
  • FunctionLIB FunctionLIB

In the FunctionLIB I use two APIs for external hardware, called SDK1.h and SDK2.h 在FunctionLIB中,我使用两个API作为外部硬件,称为SDK1.h和SDK2.h

The lib is linked by the GUI, but the GUI only includes the FunctionLIB.h lib由GUI链接,但GUI仅包含FunctionLIB.h

When building the lib, the headers are found since the include directories are set properly. 构建lib时,会找到标题,因为include目录设置正确。 But when compiling the GUI, which uses the LIB functions, I get include files not found. 但是在编译使用LIB函数的GUI时,我得到了未找到的包含文件。 I have to add the include directories to the GUI directories as well. 我还必须将include目录添加到GUI目录中。

Why is that so? 为什么会这样? The LIB finds it just fine, but the GUI indirectly throws an error, and I do not understand why it would need those includes in the first place. LIB发现它很好,但GUI间接抛出错误,我不明白为什么它首先需要那些包含。

If you make a library, you should have one (or more) public header files, that are included by the code that needs your library. 如果您创建了库,则应该有一个(或多个) 公共头文件,这些文件包含在需要您的库的代码中。 However, these public header files should try not to include any external libraries used internally by the you library. 但是,这些公共头文件应尽量不包含您库内部使用的任何外部库。

In your case, it might be enough to create two header files for your library. 在您的情况下,为您的库创建两个头文件可能就足够了。 One public, and one private that includes the public header file and the external header files. 一个公共,一个私有,包括公共头文件和外部头文件。 Then in your library you only include the private header file. 然后在您的库中,您只包含私有头文件。

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

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