Visual Studio: What exactly are lib files (used for)?

前端 未结 3 1058
谎友^
谎友^ 2021-01-13 09:43

I\'m learning C++ and came across those *.lib files that are obviously used by the linker. I had to set some additional dependencies for OpenGL.

  • What exactly a
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-13 10:17

    .lib files are "libraries" and contain "collections" of compiled code so-to-speak. So it is a way to provide software components, without giving away the internal source-code for example. They can be generated as "output" of a "build" just like executables are.

    The specific contents depend on your platform / development environment, but they will contain symbols for the linker to "hook up" function-calls provided by e.g. the header-file of the library.

    Some libraries are "dynamic" (.DLL's on Windows), which means the "hooking" of function-calls is setup when the executable using the library is loaded, allowing the library implementation to be changed without rebuilding the executable.

    One last thing. You say you're learning C++, and a common confusing point is, that "symbols" generated by C++ compilers are "mangled" (in order to allow e.g. function overloading), and this "mangling" is not standardized across different compilers, so libraries often resort to C for the "API" of the library (just like OpenGL), even though the library may be implemented in C++ internally.

    I hope shed some light on .lib-files. Happy OpenGL coding :-)

提交回复
热议问题