等效于Linux中的导入库 [英] Equivalent of import libraries in Linux

查看:103
本文介绍了等效于Linux中的导入库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Windows C ++中,当您要链接到DLL时,必须提供一个导入库.但是在GNU构建系统中,当您想链接.so文件时,就相当于您不希望使用的dll.为什么是这样?是否有等效的Windows导入库.

In Windows C++ when you want to link against a DLL you must supply an import library. But in GNU build system when you want to link against .so files which are the equivalent of dll you don't. Why is this? Is there an equivalent of Windows import libraries.

注意:我不是说在Windows中使用GNU C ++的情况,在这种情况下您也必须使用导入库.分隔线在Windows C ++和Linux C ++之间.

Note: I don't speak about the case where you use GNU C++ in Windows where you have to use import libraries as well. The splitting line is between Windows C++ and Linux C++.

推荐答案

在Windows和Linux中,链接模型是不同的.阅读Levine的书 链接器和加载器 (在Linux上,每个公共符号除非您在Windows上播放可见性技巧,否则将导出="noreferrer">库; ,情况并非如此,并且导出的符号需要明确显示.)

The linking model is different in Windows and in Linux. Read Levine's book Linkers and loaders (on Linux, every public symbol of a library is exported, unless you play visibility tricks; on Windows, that is not the case, and exported symbols need to be explicited).

C ++ 11 标准(请阅读

The C++11 standard (read n3337) don't mention dynamic linking. It is an implementation detail.

未来的 C ++ 20 可能会有有关更多详细信息,请注意名称处理是不同的.另请参阅 程序库操作方法 ,Drepper的 如何编写共享库

For more details, be aware that name mangling is different. Read also Program Library Howto, Drepper's How to Write Shared Libraries

在Linux上,插件已加载(并分别处理(在Windows上),则动态加载器.参见 ld-linux(8) dlopen(3)

On Linux, plugins are loaded (and handled differently than on Windows) by the dynamic loader. See ld-linux(8), dlopen(3), dlsym(3), elf(5)

在Linux上检查 ELF 文件(可执行文件)和 nm(1).

Inspect, on Linux, ELF files (object files, libraries, executables) with objdump(1) and readelf(1) and nm(1).

另请参见 C ++ dlopen mini howto .另请参阅可见性函数问题.

See also C++ dlopen mini howto. Read also about the Visibility function attribute. See also this question.

.so文件,相当于dll

.so files which are the equivalent of dll

Linux 共享对象( en.wikipedia.org/wiki/Dynamic-link_library"rel =" noreferrer> DLL .阅读上面给出的参考.

A Linux shared object (ELF .so file) is not exactly equivalent to a Windows DLL. Read the references given above.

我还建议您阅读 操作系统:三件简单的书 和旧的 高级Linux编程 (均可免费下载) .稍后阅读 syscalls(2)以及从那里引用的页面.

I also recommend reading Operating Systems: Three Easy Pieces and the old Advanced Linux Programming (both are freely downloadable). Later read syscalls(2) and the pages referenced from there.

还要注意,Linux是免费软件,因此您可以下载并研究源代码.它的大部分组件.

Be also aware that Linux is free software, so you can download and study the source code of most of its components.

PS. Linux和Windows确实不同.不要期望在Linux中找到与每个Windows功能完全相同的功能. 以崭新的眼光看Linux.利用Linux由自由软件组成的优势,并考虑研究源代码,例如内核 binutils ,GNU libc musl-libc (都提供了一些ld-linux.solibc.so,因此提供了 GCC C语(均提供

PS. Linux and Windows are really different. Don't expect to find in Linux the exact equivalent of every Windows feature. Look into Linux with fresh eyes. Take advantage that Linux is made of free software, and consider studying the source code e.g. of the kernel, binutils, GNU libc or musl-libc (both providing some ld-linux.so and libc.so, so a C standard library), GCC or Clang (both providing a C++ standard library above the libc.so).

这篇关于等效于Linux中的导入库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆