English 中文(简体)
Visual Studio: lib文件是用来做什么的?
原标题:Visual Studio: What exactly are lib files (used for)?

我正在学习C ++,遇到了显然由链接器使用的那些* .lib文件。 我必须为OpenGL设置一些附加依赖项。

  • What exactly are library files in this context used for?
  • What are their contents?
  • How are they generated?
  • Is there anything else worth knowing about them?

或者它们只是可重新定位的目标代码,类似于* .obj文件?

最佳回答

简言之,是的——校正档案只是收集的。

There is a slight complication on Windows that you can have two classes of lib files.
Static lib files essentially contain a collection of .obj and are linked with your program to provide all the functions inside the .lib. They are mainly a convenience to save you having as many files to deal with.

There are also stub .lib which provide just the definitions of functions which are contained in a .dll file. The .lib file is used at compile time to tell the compiler what to expect from the function, but the code is loaded at run time from the dll.

问题回答

.lib文件是“库文件”,包含“编译代码的集合”,可以说是提供软件组件的一种方式,而不必泄露内部源代码。它们可以像可执行文件一样作为“构建”的“输出”生成。

具体内容取决于您的平台/开发环境,但它们将包含连接器的符号,以“挂钩”由库的头文件提供的功能调用。

一些库是“动态”的(在Windows上是.DLL),这意味着当使用库的可执行文件被加载时设置函数调用的“钩子”,允许在不重新构建可执行文件的情况下更改库实现。

最后一件事。你说你正在学习C++,一个常见的困惑点是,由C++编译器生成的“符号”是“混淆的”(为了允许例如函数重载),而这种“混淆”在不同的编译器中不是标准化的,因此库经常使用C来实现库的“API”(就像OpenGL一样),即使库在内部是使用C++实现的。

我希望能为.lib文件提供一些帮助。愉快的OpenGL编程 :-)

What exactly are library files in this context used for?

它们是像您的可执行文件一样编译和链接的代码。它们被称为静态库,其他程序可以在编译时链接到它们。在OpenGL的情况下,您链接到它们的库以构建可以运行OpenGL代码的可执行文件。动态库(DLL)是可执行文件在运行时链接的另一种库类型。

他们的内容是什么?

静态库包含链接的目标代码,就像可执行文件一样。*.obj文件是编译器为链接器生成的目标代码。

它们如何生成?

当编译器创建目标文件时,它将工作传递给链接器。您可以像可执行文件一样在开发环境中创建它们。

Is there anything else worth knowing about them?

他们在任何地方都再次使用Yah,因此没有伤害他们。





相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签