What’s the deal with OLDNAMES.LIB?

栏目: IT技术 · 发布时间: 4年前

Set the time machine to 1988. The C language has not yet been standardized. Everybody had their own libraries for doing stuff, and some of them even pretended to be compatible with each other. The Microsoft C compiler, for example, came with a bunch of functions like unlink and stat to provide sort-of compatibility with Unix-sort-of source code.

And then the C standard was ratified in 1989. Now things got interesting, because those functions were not part of the C standard. Standard-conforming C programs were welcome to define functions with those names, and the rules say that this is perfectly legal and are not references to the identically-named Unix-like functions.

Now, there was a lot of code written for the Microsoft C toolchain that used these sort-of-Unix-ish functions, and renaming those functions would cause those programs to break.

So should we rename the Unix-ish functions in the Microsoft C library, in order to conform to the C standard? Or should we leave the functions in the Microsoft C library under their pre-standard names, to keep existing code working?

Let’s do both !

The Microsoft C library renamed these Unix-ish function to have a leading underscore. So unlink became _unlink , and so on. A program that didn’t use the Unix-ish library functions could define its own function called unlink , and everything would work just fine. But if the program actually wanted to use the unlink function from the Unix-ish library, this magic library OLDNAMES.LIB would step in.

The OLDNAMES.LIB library doesn’t contain any code of its own. Rather, it contains name redirections that say, “Hey, I have a symbol called unlink , in case you were looking for it. Wait, you want to know what this symbol represents? Um, it represents a symbol named _unlink . Good luck with that.”

If the linker cannot find a symbol named unlink , it turns to OLDNAMES.LIB as a library of last resort, and that library resolves the symbol unlink , but replaces it with an unresolved symbol named _unlink . The linker then goes through the symbol resolution process again, and this time it finds _unlink in the regular C library.

The net result is that your attempt to call the function unlink got redirected to the function _unlink , but only if you didn’t already have a function named unlink .

You can suppress the OLDNAMES.LIB library in various ways, most notably by passing the /NODEFAULTLIB flag, which can be abbreviated to the somewhat enigmatic /NOD .


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Linux内核完全剖析

Linux内核完全剖析

赵炯 / 机械工业出版社 / 2006-1 / 79.00元

本书对早期Linux操作系统内核全部代友文件进行了详细的剖析,旨在让读者在尽量短的时间内对Linux的工作机理获得全面而深刻的理解,为进一步学习和研究Linux系统打下坚实的基础。虽然选择的版本较低,但该内核已能够正常编译运行,并且其中已包括了Linux工作原理的精髓。书中首先以Linux源代码版本的变迁为主线,简要介绍了Lin-ux系统的发展历史,同时着重说明了各个内核版本之间的主要区别和改进方......一起来看看 《Linux内核完全剖析》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具