下面的声明/关键字背后的解释是什么?

发布于 2024-07-14 02:56:02 字数 215 浏览 5 评论 0原文

我想知道以下声明的作用。 我在 MSVisual Studio 上的 C 代码中看到过它们编译的代码。

extern "C" __declspec(dllexport)

extern "C" __declspec(dllimport)

我知道一些它们用于声明函数的外部链接(在不同源文件中定义的函数。但想详细了解它是如何工作的。

-Ajit

I would like to know what the following declarations do. I have seen them in a C code on MSVisual Studio Compiled code.

extern "C" __declspec(dllexport)

extern "C" __declspec(dllimport)

I know somewhat that they are used to declare external linkage for functions(functional defined in different source file.But would like to know in detail how this works.

-Ajit

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

记忆で 2024-07-21 02:56:02

extern "C" 部分告诉 C++ 编译器所声明的项应使用 C 链接,这意味着该名称不会被破坏(或者将以与 C 编译器相同的方式被破坏) )。 这使得该项目可以从 C 代码和大多数其他语言链接到,因为 C 链接通常是平台上使用的标准。

__declspec(dllexport)__declspec(dllimport) 项是非标准属性,它们告诉编译器应从 DLL 导出(或导入)该项。 MS 编译器以及可能其他面向 Windows 的编译器支持 __declspec() 属性。 我不确定 GCC 是否这样做。 可以使用 __declspec() 指定的其他存储类属性(至少在 MSVC 中)包括 uuid()、naked、deprecated 以及其他为编译器提供有关如何编译对象或函数的信息的内容。

The extern "C" part tells a C++ compiler that the item being declared should use C linkage, which means that the name will not be mangled (or will be mangled in the same way that a C compiler would). This makes it so the item can be linked to from C code and most other languages as well, since C linkage is typically the standard used for that on a platform.

The __declspec(dllexport) and __declspec(dllimport) items are non-standard attributes that tell the compiler that the item should be exported (or imported) from a DLL. The __declspec() attribute is supported on MS compilers and probably other compilers that target Windows. I'm not sure if GCC does or not. Other storage class attributes that can be specified with __declspec() (at least in MSVC) include uuid(), naked, deprecated and others that provide the compiler with information on how an object or function should be compiled.

雨后咖啡店 2024-07-21 02:56:02

dllexport 告诉编译器生成 .lib 文件。 dllimport 告诉编译器在 .lib 文件中查找函数声明(其定义将在 dll 中)。

dllexport tells the compiler to generate a .lib file. dllimport tells the compiler to look in a .lib file for the function declaration (its definition will be in a dll).

可爱暴击 2024-07-21 02:56:02

这意味着它后面的函数/类是可见的并且可以跨 DLL 边界访问,因此您可以链接它们并从其他代码调用它们

It means the functions/classes that follow it are visible and accessible across a DLL boundary so you can link against them and call them from other code

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文