为什么必须链接库并设置包含目录
嘿,所以我有点困惑为什么,在 msVS++ 2010 中,当所有头文件和 cpp 文件都位于静态库或静态库项目中时,您必须包含目录就我而言。
我用 cmake 制作了静态库项目,我被告知将其设置为的源文件与我现在被告知制作包含目录的源文件相同...似乎我有 2 个相同的 cpp 和头文件...除了我的解决方案中静态包含的头文件...为什么?
Hey so i'm a little confused on why, in msVS++ 2010 you have to have include directories when all the headers and cpp files are inside the static libray or static library project in my case.
I made the static library project with cmake, and the source file i was told to set it to is the same i'm now told to make the include directory... it seems like I have 2 of the same cpp and header files.. except ones included statically in my sollution... WHY?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
因为VS++在抽象底层实现的同时并没有完全隐藏它。
包含目录和库针对过程的不同阶段,传统上由不同的程序处理。包括预处理器的目录、链接器的库。这些程序现在被称为(或一部分?)VC++,但其界面仍然显示底层结构。
有些系统允许使用编译指示在源代码(以及头文件)中标记所需的库。它们有几个缺点:
非标准
您不能轻松地用另一个库替换库(例如调试/检测/发布、单线程/多线程,...)
Because VS++ while abstracting the underlying implementation does not hide it completely.
Include directories and libraries are targeted at different phase of the process, which are traditionally handled by different programs. Include directories by the preprocessor, libraries by the linker. Those programs are now called (or part of?) VC++, but its interface still shows the underlying structure.
There are systems which allows to mark the needed libraries in the source code (and thus in the header) by the use of pragmas. Those have several disadvantages:
non standard
you can't as easily substitute libraries by another (say debug/instrumented/release, single thread/multi thread, ...)
头文件告诉您您正在调用的函数。
静态库包含您正在调用的函数的代码,但不包含有关如何调用它们的信息。
Header files tell you about the functions you're calling.
Static libraries include the code of the function you're calling, but not information about how to call them.