DLL:导出为 C/C++ 函数? [英] DLL : export as a C/C++ function?

查看:27
本文介绍了DLL:导出为 C/C++ 函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从 C++ 代码在 Visual 中生成了一个 DLL.Dependency Walker 看到 3 个函数导出为 C 函数.

I generated a DLL in Visual from a C++ code. Dependency Walker sees 3 functions exported as C functions.

我做了一个 SCons 项目来生成 DLL,3 个函数中有 2 个不是 C 函数.

I made an SCons project to do the generate the DLL, and 2 of the 3 functions are not seen as C functions.

是什么让函数被视为或 C++ 函数而不修改代码?它必须在编译/链接选项中,但我没有找到任何相关内容.

What makes a function seen as a or C++ function, without modifying the code ? It must be in the compilation/linking options, but I didn't find any relevant thing.

该函数以宏为前缀:AM_LIB_EXPORT

The function are prefixed by a macro : AM_LIB_EXPORT

在 .h 中,我有:

#ifdef _WIN32
#define AM_LIB_EXPORT __declspec(dllexport)
#else
#define AM_LIB_EXPORT
#endif // _WIN32

谢谢.

推荐答案

是什么让函数被视为或 C++ 函数而不修改代码?

What makes a function seen as a or C++ function, without modifying the code ?

由 C++ 编译器编译的函数自动成为C++ 函数",并且会发生名称修改以解析 C++ 功能,例如命名空间和重载.为了获得C"导出名称,必须在函数声明中使用上述 extern "C" 限定符.或者,在包含原型的标题周围有一个巨大的 extern "C" { .. } 块.

A function compiled by a C++ compiler is automatically a 'C++-function' and name-mangling occurs to resolve C++ features such as namespaces and overloading. In order to get 'C' export names, one must use the aforementioned extern "C" qualifier in the function declaration. Alternatively a huge extern "C" { .. } block around the header containing the prototypes.

如果这不能解决您的问题,则可能与 dllimport/dllexport 有关.如果您在 DLL 构建中 #define AM_LIB_EXPORT __declspec(dllexport),您通常还需要为链接到您的 DLL 的应用程序设置 dllimport,以便链接器知道从哪里获取符号.

If this does not solve your issue, its maybe related to dllimport/dllexport. If you #define AM_LIB_EXPORT __declspec(dllexport) in your DLL build, you'll typically also need to make it dllimport for apps linking against your DLL in order for the linker to know where to fetch the symbols from.

这篇关于DLL:导出为 C/C++ 函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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