vc++External Dependencies

本文介绍在软件项目中如何正确组织和引用源代码、头文件、资源文件等,并解释了External Dependencies的作用及其添加方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

External   Dependencies是说你没有把这个文件加入到这个工程中,但是需要这个文件的支持。当然有时是误操作。比如你从工程里面删除了abc.h但是在其中一个文件中用#include包含了这个文件,那么,abc.h就会进入External   Dependencies中。

.cpp文件比必须加到工程的Source Files中,否则编译link时候总是出错。而加进去就没有问题。
     .h则可以不加,如果不加的话,会自动到External Dependencies中。好像所有的.h文件都不必加到Header Files文件夹下面。包括Resource.h这个头文件,不过这个头文件在编译链接的过程中也并不加到External Dependencies里面。还有就是Dlg.h(主对话框及子对话框)也同样不需要加到Head Files中。
     针对Source Files里面的文件来说,.rc文件可以不用加,这样Compile,Link也没错,其他的.cpp文件必须都得加上的。
总的来说一句话:
     工程中包含的头文件、库文件,若不在当前目录下,就会放在external Dependencies下。

Source Files 放源文件(.c、.cpp)程序的实现代码全放在这里
Header Files 放头文件(.h)声明放在这里
Resource Files 资源文件(.rc)放图标、图片、菜单、文字之类的,主要用来做界面的东东一般都放这里
External Dependencies 除上三种以外的,程序编译时用到的文件全放这里.

我刚查了下相关资料,告诉你它如何将某个文件(如PROTOCOL.H)添加到它的下面:  
   在工程目录下再建一个目录,比如目录名为additional  
   Project->Setting->C/c++  
   选择Catalog为Preprocessor,在Additional   Include   Directory   里面加入刚才建的目录名  

   即additional就可以了,这样在该目录下的文件,然后你在工程中编译程序,改头文件就会出现在External   Dependencies目录里面。

   如果这个文件为工程的同级文件,只需写入..\addtional就可以找到了。
另外补充一点:  
   还可以讲*.lib文件放到我们自己所建立的文件夹比如additional里,然后再对工程进行设置,其步骤如下:  
   Project->Setting->Link-选择Category为Input,在Additional   Linbrary   path里填入你所建立的文件夹即additional即可,然后对程序进行编译程序即可找到我们的库文件*.lib了。   

如果这个文件为工程的同级文件,只需写入..\addtional

    
   这样做的好处是可以把我们的头文件和库文件一起放在一个我们所建立的文件夹中,方便管理。而且头文件中所声明的类也不会在Workplace中的Class   View中显示出来。免得显得乱七八糟的。 

### VC++ Static Library Usage and Configuration Static libraries in Visual C++ are collections of object files that can be linked into an executable during compilation. When using static libraries, developers must ensure proper linkage between the application code and the library. To use a static library effectively: - Include necessary header files from the static library within the project's source files. For instance, if `mylib` is a custom-built static library, include its headers at the top of relevant `.cpp` files[^2]: ```cpp #include "stdafx.h" #include "mylib/myheader.h" ``` - Link against the static library by adding it to the linker input settings through Project Properties -> Linker -> Input -> Additional Dependencies[^1]. For configuring static libraries correctly: - Ensure all required dependencies specified via `target_link_libraries()` when building with CMake projects. - Place precompiled headers like `stdafx.h`, which facilitates faster builds especially useful for large-scale applications, ensuring these appear before any other includes in each translation unit where applicable. - Verify compatibility among different components involved; mismatches may lead to issues such as unresolved external symbols or type conflicts unless carefully managed[^5]. When encountering errors related to classes or namespaces not being recognized while working on static libraries, verify whether appropriate forward declarations exist alongside correct inclusion paths set up properly within both the IDE environment setup along with build scripts used. ```cpp // Example demonstrating linking a static lib named 'exampleLib' #pragma comment(lib,"path\\to\\exampleLib.lib") int main(){ // Use functions defined inside exampleLib here... } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值