c++ - 'operator new' : redefinition, 不同的链接(在重新定义的新运算符上使用 _dllspec)

标签 c++ dll linker extern

我在 new 的调试版本上使用 __declspec(dllimport/export):

#ifdef _DEBUG
 DECLSPECCORE extern   void* operator new(unsigned int size, const char* file, int line);
 extern void* operator new[](unsigned int size, const char* file, int line);
 extern void operator delete(void* address, const char* file, int line);
 extern void operator delete[](void* address, const char* file, int line);
 extern void Delete(void* address);

#define LUDO_NEW new(__FILE__, __LINE__)
#define LUDO_DELETE delete

#endif

这让我得到了

error C2375: 'operator new': redefinition; different linkage.

这是为什么?如何解决?这是我目前正在编译的唯一项目。

最佳答案

C++ 运行时本身提供了一个 operator new,它没有被标记为 DECLSPECCORE —— 因此是“不同的链接”,原始的不是从另一个模块导入的。如果您打算覆盖 operator new,它应该具有与以前相同的链接。

关于c++ - 'operator new' : redefinition, 不同的链接(在重新定义的新运算符上使用 _dllspec),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1567972/

相关文章:

c++ - 在 C++ 中导入 DLL 并使用 extern 函数

c# - 在C#应用程序中导入并调用COM dll

linux - g++ -static 标志替换动态库加载器

dll - 链接到 V8 快照

c++ - 在我的类头文件中的预编译头文件中包含头文件并在其外部包含头文件

c++ - "cannot open include file"错误在 Visual C++ 2010 中意味着什么?

visual-c++ - VS 2013 找不到资源编译器DLL。请确保路径正确

lua - ld : warning: ignoring file liblua. a,为 macOS-x86_64 构建,但尝试链接为未知不支持的文件格式构建的文件(0x21 0x3C

c++ - 如何从 vector<Rect> 中删除重复矩形?

c++ - std::map已知位置删除摊余的复杂度和红黑树重新着色的次数