vc中使用lib方法 & 预处理(Propreprocessor)

来源:互联网 发布:数字图像处理经典算法 编辑:程序博客网 时间:2024/06/10 09:06

一,vc6.0 中使用lib文件 使用库的方法如下:
第一步. 包含库的头文件
在应用程序工程中使用
#include "file path"
file path可以为绝对路径,也可以为相对于工程所在目录的相对路径

如果头文件比较多,可以在project>settings>c/c++>preprocessor的Additional include directories中填入你的头文件所在目录

若光进行第一步,而没有第二步,将会报相关函数错误

第二步. 导入lib库。导入的方法很多
1) 直接用project>add to project>files的方式将.lib加入工程
2) 使用#pragma指令,如
#pragma comment(lib, "your lib path and name")
与前面头文件一样,也可以不在这里指定路径,而是在project>settings>link>input的Additional library path中输入.lib文件所在路径
3) 还可以在project>settings>link>general的ojbect/library modules中输入.lib的名字

3. 编译执行程序,如果是静态库,编译后就可直接执行
如果是动态库,需要将dll放到可执行文件所在目录下,或者系统目录下,如system32或者windows目录,或者其它任何一个位于环境变量PATH中的目录


vc.net 中使用lib文件

1、视图->属性页   
2、在属性页的左边,点击链接器的图标,会弹开   
3、点一下弹开后的 输入,然后看右边,出来一个表,第一排是附加依赖项。


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/flyingstarwb/archive/2008/07/30/2739742.aspx

 

二,预处理

预处理即编译的第一次扫描,比如词法,语法分析等工作。

预处理包含文件包含命令include,宏命令#define等,这里主要讲述include命令。include命令主要是将库函数包含到当前的程序内,将制定的文件与当前的源程序连成一个文件。

 

 

The C++ preprocessor runs before any other compilation happens. Commands given to the preprocessor allow the programmer to define variables, perform text substitution, and test simple conditions.

# and ##manipulate strings#definedefine macrodefinition#errordisplay an error message#if, #ifdef, #ifndef, #else, #elif, and #endifconditional operators#includeinsert the contents of another file#lineset line and file information#pragmaimplementation specific command#undefused to undefine macrodefinitionsPredefined preprocessor variablesmiscellaneous preprocessor variables

 

 

一般include包含头文件,如果没有该头文件,则某些变量的定义会出现未定义。比如在cximage中,添加lib库时要包含#include "ximage.h",否则定义类对象CxImage  image;时会出现未定义的错误。因为预处理的时候会分析语法CxImage  image的出处。