如何解决从dll导出的函数的stdint标头
我有一个标头,用于从DLL中导出某些方法,该方法可以从C和C ++代码中使用:
#ifdef __cplusplus
extern "C"
{
#endif
API_EXPORT uint32_t __cdecl GetSomeValue();
#ifdef __cplusplus
}
#endif
对于uint32_t,我需要包含一个标头,但是哪个是正确的?
选项1:
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdint.h>
选项2:
#ifdef __cplusplus
extern "C"
{
#endif
#include <cstdint>
选项3:两者。
#ifdef __cplusplus
extern "C"
{
#include <cstdint>
#else
#include <stdint.h>
#endif
解决方法
您...只需添加标题即可。
#include <stdint.h>
#ifdef __cplusplus
extern "C"
{
#endif
API_EXPORT uint32_t __cdecl GetSomeValue();
#ifdef __cplusplus
}
#endif
您不需要在内置标头周围使用extern "C" {}
。 (有时您可能会找到需要它的库)
您的选项2通常不能与C编译器一起使用,所以可以了。您的选项1或@ user253751的答案中介绍的变体应该没问题,但是如果您考虑防止bug的C,C ++或标准库实现,那么我会在选项3中使用这种变体:
#ifdef __cplusplus
#include <cstdint>
extern "C"
{
#else
#include <stdint.h>
#endif
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。