收录查询

到底我的应用程序中需要用几个import库??你怎么知道??

DEMO:[VC6.0+SP5  && C++->code generate(debug single thread)]

/* const相关的各种情况的测试 */
#include<iostream>
// #include<yvals.h>             /* namespace std在此文件中定义,只为说明std命名空间定义在此头文件*/
using namespace std;

int main()
{
 const int iNum=100;
 const int * const pNum=&iNum; /* int const * const pNum=&iNum;*/
 
 cout<<"iNum="<<iNum<<endl;
 cout<<"pNUm="<<pNum<<endl;
 cin.get();
 return 0;
}


编译和连接的时候:指定LINKER选项Object/Library Modules为: /verbose:lib(别罗嗦!我只看加载了哪些LIB)

BUILD标签页窗口中向你展示了加载了哪些库:

Linking...
Searching Libraries
    Searching D:\VS6.0\VC98\LIB\libcpd.lib:
    Searching D:\VS6.0\VC98\LIB\LIBCD.lib:
    Searching D:\VS6.0\VC98\LIB\OLDNAMES.lib:
    Searching D:\VS6.0\VC98\LIB\kernel32.lib:
    Searching D:\VS6.0\VC98\LIB\libcpd.lib:
    Searching D:\VS6.0\VC98\LIB\LIBCD.lib:
    Searching D:\VS6.0\VC98\LIB\OLDNAMES.lib:
Done Searching Libraries

[MSDN]:

/NODEFAULTLIB[:library]

This option tells the linker to remove one or more default libraries from the list of libraries it searches when resolving external references.

Command Line Project Settings Description
/NODEFAULTLIB:library Ignore Libraries This option removes the specified library or libraries from the list of libraries it searches when resolving external references.
/NODEFAULTLIB Ignore All Default Libraries This option removes all default libraries from the list of libraries it searches when resolving external references.

To find this option in the development environment, click Settings on the Project menu. Then click the Link tab, and click Input in the Category box.

The linker resolves references to external definitions by searching first in libraries specified in the Object/Library Modules text box in the Project Settings dialog box (or on the command line), then in default libraries specified with the /DEFAULTLIB option, and then in default libraries named in .OBJ files.

To specify multiple libraries, type a comma (,) between the library names.

The Ignore Libraries (/NODEFAULTLIB:library) option overrides /DEFAULTLIB:library when the same library name is specified in both.

然后,使用 /NODEFUALTLIB:OLDNAMES.lib来忽略掉我们的程序中可能不会加载的LIB(不需要的比较少的时候,通过它来排除一些LIB库,当然你不能勾选“ignore default library”)
递归使用上面的方法就可以知道你的应用程序必须要加载哪些LIB文件

比如:要想成功编译和连接上面的DEMO,至少要有3个连接时的import库

    Searching D:\VS6.0\VC98\LIB\kernel32.lib:
    Searching D:\VS6.0\VC98\LIB\LIBCD.lib:
    Searching D:\VS6.0\VC98\LIB\libcpd.lib:
========================================================================
那你说:天知道我要用到哪些库
那就让LINKER自己去你的库路径下面找吧:LINK->Generate->Object/Library Modules里面什么都不要填写(别勾选:ignore default library选项,因为勾选了它你必须对你要用什么LIB非常清楚,只根据你指定的LIB来LINK)
这样LINKER会在你设置的:Tool->Option->Directory->Show directory for(Library Files)中指定的位置去加载你的应用程序需要用到的LIB

posted @ 2005-12-31 05:27  ->  阅读(511)  评论(0)    收藏  举报