链接器、库和目录信息
我已经完成了 C++ 1/2 课程,但我们没有介绍任何有关链接到库或向 C++ 代码添加其他库的内容。
我一直在努力解决这个问题;我一直无法找到链接
对象的基本信息。最初我认为问题出在 IDE(Netbeans;和 Code::Blocks)。但是我无法获得 wxWidgets
和 GTKMM
设置。
有人可以为我指明有关 Cpp 应用程序中#includ
ing 文件和link
ing 文件的术语和基本信息吗?基本上我想/需要了解有关此过程的所有内容。 .dll
、.lib
、.o
、.lib.a
、.dll之间的区别.a
。 .h
和“库”(.dll、.lib 正确吗?)之间的区别
我知道我需要阅读我正在使用的编译器文档;然而,所有编译器(据我所知)都使用链接器和标头;我需要了解这些信息。
请指出我正确的方向! :]
到目前为止,在我的探索中,我发现:
Linker
链接已经编译到您的项目的库。.a
文件是静态库(在 Windows 中为.lib
).dll
在 Windows 中是共享库(.so
) > 在 *nix 中)
I've finished both my C++ 1/2 classes and we did not cover anything on Linking to libraries or adding additional libraries to C++ code.
I've been having a hay-day trying to figure this out; I've been unable to find basic information link
ing to objects. Initially I thought the problem was the IDE (Netbeans; and Code::Blocks). However I've been unable to get wxWidgets
and GTKMM
setup.
Can someone point me in the right direction on the terminology and basic information about #includ
ing files and link
ing files in a Cpp application? Basically I want/need to know everything in regards to this process. The difference between .dll
, .lib
, .o
, .lib.a
, .dll.a
. The difference between a .h
and a "library" (.dll, .lib correct?)
I understand I need to read the compiler documentation I am using; however all compilers (that I know of) use linker and headers; I need to learn this information.
Please point me in the right direction! :]
So far on my quest I've found out:
Linker
links libraries already compiled to your project..a
files are static libraries (.lib
in windows).dll
in windows is a shared library (.so
in *nix)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在类 Unix 系统上,您通常可以在
/usr/lib
中找到库。.a
扩展名表示您正在处理使用 ar。它们是从扩展名为.o
的对象文件创建的。然后链接器可以在编译时解析引用。它们被称为静态库,因为来自对象的机器代码 找到例如,如果您考虑数学库,您将在
/usr/bin/libm.a
中找到该库本身,并在包含目录中 相应的头文件(例如:/usr/include/math.h)。您必须为编译器包含头文件math.h
,并为链接器指定库libm.a
来解析引用,编译器留下的共享库使用扩展名
.so
。在这里,引用不是由链接器解析的。可执行文件启动后,加载器将动态查找库并根据未解析的引用将它们加载到内存中。.dll 是 Microsoft Windows 的动态链接库,我对它们不是很熟悉,但我认为所涉及的步骤是相似的。
On a Unix-like system, you usually find libraries in
/usr/lib
. The.a
extension indicates that you are dealing with an archive file created for example with ar. They are created from object files with the extension.o
. The linker can then resolve references at compile time. They are called static libraries, because the machine code from the object file is copied into the final executable.If you for example consider the math library, you will find the library itself at
/usr/bin/libm.a
and the corresponding header file in your include directory (e.g.:/usr/include/math.h). You have to include the headermath.h
for the compiler and for the linker specify the librarylibm.a
to resolve the references, which where left by the compiler.Shared libraries use the extension
.so
. They are useful if you want to have a small executable file. Here, the references are not resolved by the linker, but when the executable is started, the loader will look for the library dynamically and load them according to the unresolved references into memory..dll are dynamically linked libraries for Microsoft Windows and I am not very familiar with them, but I assume, that the steps involved are similar.