一个单例模式中使用std::unique_ptr引起的莫名其妙的COFF损坏的问题(未解决)

使用static std::unique_ptr和static std::shared_ptr都不行struct     IElementAgendaEvents
{//! Called to allow listeners to modify the agenda by adding/removing entries before applying tool operation. Return true if entries added or invalidated.virtual bool _DoModifyAgendaEntries (ElementAgendaP agenda, AgendaOperation, AgendaModify) {return false;}//! Called to allow listeners to copy additional information from source to destination not appropriate to tool operation.virtual void _OnPreCopyAgenda (ElementAgendaCP agenda, AgendaOperation, AgendaModify, ElementCopyContextP) {};//! Called before the tool operation is applied to the agenda.virtual void _OnPreModifyAgenda (ElementAgendaCP agenda, AgendaOperation, AgendaModify, bool isGroupOperation) {};//! Called after the tool operation is applied to the agenda.virtual void _OnPostModifyAgenda (ElementAgendaCP agenda, AgendaOperation, AgendaModify, bool isGroupOperation) {};//! @cond DONTINCLUDEINDOC//! Called to allow custom clipboard formats to be added for the elements in the agenda.virtual void _DoAddDeferredClipboardFormats (ElementAgendaP, AgendaOperation, AgendaModify, GuiDataObject*) {}//! Called to allow listener to participate in element set dynamics. See RedrawGroupInfo for return status meaning.virtual bool _OnRedrawGroupEvent (ElementAgendaCP, AgendaOperation, AgendaModify, RedrawGroupInfo const*) {return false;}virtual bool Dummy1 (void*) {return false;}
//! @endcond
};struct ElementAgendaEvents : public DgnPlatform::IElementAgendaEvents
{static ElementAgendaEvents&  GetInstance()
{static std::unique_ptr<ElementAgendaEvents> _Instance = nullptr; if (nullptr == _Instance)_Instance.reset(new ElementAgendaEvents());return *_Instance;
}
//...
};编译错误:
ElementAgendaEvents.obj : fatal error LNK1235: 损坏或无效的 COFF 符号表
仅使用类名生成一个对象struct     IElementAgendaEvents
{//! Called to allow listeners to modify the agenda by adding/removing entries before applying tool operation. Return true if entries added or invalidated.virtual bool _DoModifyAgendaEntries (ElementAgendaP agenda, AgendaOperation, AgendaModify) {return false;}//! Called to allow listeners to copy additional information from source to destination not appropriate to tool operation.virtual void _OnPreCopyAgenda (ElementAgendaCP agenda, AgendaOperation, AgendaModify, ElementCopyContextP) {};//! Called before the tool operation is applied to the agenda.virtual void _OnPreModifyAgenda (ElementAgendaCP agenda, AgendaOperation, AgendaModify, bool isGroupOperation) {};//! Called after the tool operation is applied to the agenda.virtual void _OnPostModifyAgenda (ElementAgendaCP agenda, AgendaOperation, AgendaModify, bool isGroupOperation) {};//! @cond DONTINCLUDEINDOC//! Called to allow custom clipboard formats to be added for the elements in the agenda.virtual void _DoAddDeferredClipboardFormats (ElementAgendaP, AgendaOperation, AgendaModify, GuiDataObject*) {}//! Called to allow listener to participate in element set dynamics. See RedrawGroupInfo for return status meaning.virtual bool _OnRedrawGroupEvent (ElementAgendaCP, AgendaOperation, AgendaModify, RedrawGroupInfo const*) {return false;}virtual bool Dummy1 (void*) {return false;}
//! @endcond
};struct ElementAgendaEvents : public DgnPlatform::IElementAgendaEvents
{static ElementAgendaEvents&  GetInstance()
{static ElementAgendaEvents obj;return obj;}
//...
};编译成功
使用std::unique_ptr和std::shared_ptr是可以的。
因为如果使用了static,说明这个变量是要被“暴露”在外面的,它虽然在函数内部,但它的名字是和其他函数一样,暴露在外面。struct     IElementAgendaEvents
{//! Called to allow listeners to modify the agenda by adding/removing entries before applying tool operation. Return true if entries added or invalidated.virtual bool _DoModifyAgendaEntries (ElementAgendaP agenda, AgendaOperation, AgendaModify) {return false;}//! Called to allow listeners to copy additional information from source to destination not appropriate to tool operation.virtual void _OnPreCopyAgenda (ElementAgendaCP agenda, AgendaOperation, AgendaModify, ElementCopyContextP) {};//! Called before the tool operation is applied to the agenda.virtual void _OnPreModifyAgenda (ElementAgendaCP agenda, AgendaOperation, AgendaModify, bool isGroupOperation) {};//! Called after the tool operation is applied to the agenda.virtual void _OnPostModifyAgenda (ElementAgendaCP agenda, AgendaOperation, AgendaModify, bool isGroupOperation) {};//! @cond DONTINCLUDEINDOC//! Called to allow custom clipboard formats to be added for the elements in the agenda.virtual void _DoAddDeferredClipboardFormats (ElementAgendaP, AgendaOperation, AgendaModify, GuiDataObject*) {}//! Called to allow listener to participate in element set dynamics. See RedrawGroupInfo for return status meaning.virtual bool _OnRedrawGroupEvent (ElementAgendaCP, AgendaOperation, AgendaModify, RedrawGroupInfo const*) {return false;}virtual bool Dummy1 (void*) {return false;}
//! @endcond
};struct ElementAgendaEvents : public DgnPlatform::IElementAgendaEvents
{static ElementAgendaEvents&  GetInstance()
{/*static*/ std::unique_ptr<ElementAgendaEvents> _Instance = nullptr; if (nullptr == _Instance)_Instance.reset(new ElementAgendaEvents());return *_Instance;
}
//...
};编译成功

看到网上有人说这是一个编译器的bug:

有文章解释如下:

LNK1254, LNK1284, and LNK1235 linker errors may occur while compiling a C source file with the /clr compiler option (822329)

LNK1254, LNK1284, and LNK1235 linker errors may occur while compiling a C source file with the /clr compiler option (822329)



The information in this article applies to:
 
  • Microsoft Visual C++ .NET (2003)
  • Microsoft Visual C++ .NET (2002)

SYMPTOMS

When you compile a C source file (unmanaged source) with other managed source files that refer to symbols that are defined in the unmanaged source, and you specify the /clr compiler switch, you receive the following linker error message in Visual C++ .NET 2002:

LINK : fatal error LINK1254: metadata for symbol symbol name inconsistent with COFF symbol table

You receive the following linker errors in Visual C++ .NET 2003:

<managed object file>: fatal error LNK1284: metadata inconsistent with COFF symbol table: symbol '<symbol-name>' (0A000008) mapped to '<symbol-name>' (06000001) in <unmanaged object file>

<unmanaged object file>: fatal error LNK1235: corrupt or invalid COFF symbol table

CAUSE

The earlier versions of Visual C++ may not support the C or C++ source files with the /clr switch because earlier versions of Visual C++ do not have managed code or the /clr switch.

RESOLUTION

Compile the unmanaged source (including the C source files) into an object file. Similarly, compile files that constitute the managed files of the project into another object file. Link the object files that are generated from the managed and unmanaged source files into a single executable by using the linker. The following steps assume that you have unmanaged source in UnManaged.c and that you have managed source in Managed.cpp. To build your project, follow these steps:
  1. Compile UnManaged.c with the following command:
    cl /c UnManaged.c
  2. Compile Managed.cpp with the following command:
    cl /clr /c Managed.cpp
  3. Link the object files that are generated in steps 1 and 2 with the following command:
    link /NODEFAULTLIB:LIBC Managed.obj UnManaged.obj

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. Paste the following code in Notepad, and then save the file as UnManaged.h:
    #include <stdio.h>// Both of these generate LNK1254 in 2002//Generates LNK1235 - In 2003
    //int willNotLink(unsigned char data[20]);
    //int willLink(unsigned char *data);//Generates LNK1284 - In 2003
    int willLink(unsigned char data[20]);
    int willNotLink(unsigned char *data);
  2. Paste the following code in Notepad, and then save the file as UnManaged.c:
    //defines two functions to be referred in a C++ file.
    #include "UnManaged.h"int willLink(unsigned char *data)
    {printf("This is the function named willLink\n");return 0;
    }int willNotLink(unsigned char data[20])
    {printf("This is the function named willNotLink\n");return 0;
    }
  3. Paste the following code in Notepad, and then save the file as Managed.cpp:
    // This is the main file.#pragma onceextern "C"
    {
    #include "UnManaged.h"
    }#using <mscorlib.dll>using namespace System;namespace LinkerProblem
    {public __gc class Class1{public:void test(){unsigned char data[20];willLink(data);willNotLink(data);}};
    };void main()
    {LinkerProblem::Class1 *myClass = new LinkerProblem::Class1();myClass->test();
    }
  4. At the Visual C++ .NET command prompt, type the following command:
    cl /clr Managed.cpp UnManaged.c
  5. Notice that you receive the linker problem that is described in the "Symptoms" section. In Visual C++ .NET 2002, you receive the LNK1254 linker error, and in Visual C++ .NET 2003 you receive the LNK1284 linker error.
  6. To see the LNK1235 linker error in Visual C++ .NET 2003, modify the contents of the UnManaged.h header file. To do this, uncomment the two declarations under the following comment:
    //Generates LNK1235 - In 2003
    and then comment the two declarations under the following comment:
    //Generates LNK1284 - In 2003
  7. Compile the code by running the command that is specified in step 4 at the Visual Studio .NET 2003 command prompt. You receive the LNK1235 linker error in Visual C++ .NET 2003.

Modification Type:MinorLast Reviewed:1/17/2006
Keywords:kbCompiler kbAppDev kbprb KB822329 kbAudDeveloper

©2004 Microsoft Corporation. All rights reserved.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/5395.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【Vue 2.x】学习vue之一基础部分

文章目录 Vue 一基础部分第一章1、git两个分支主分支子分支 使用方法方式1&#xff1a;采用命令的方式操作分支方式2&#xff1a;在idea中使用git的分支 向git远程仓库提交时忽略文件使用git时的一些冲突注意事项 2、Vue问题1&#xff1a;什么是Vue&#xff1f;问题2&#xff1…

Activiti7 开发快速入门【2024版】

记录开发最核心的部分&#xff0c;理论结合业务实操减少废话&#xff0c;从未接触工作流快速带入开发。假设你是后端的同学学过JAVA和流程图&#xff0c;则可以继续向后看&#xff0c;否则先把基础课程书准备好先翻翻。 为什么要工作流 比起直接使用状态字段&#xff0c;工作…

dvwa kali SQL注入

high: 1.txt的来源 1.txt的内容 手动添加&#xff1a; id1&SubmitSubmit 执行&#xff1a; sqlmap -r /root/1.txt -p id --second-url "http://192.168.159.128:20000/vulnerabilities/sqli_blind/" --batch medium&#xff1a; 换链接&#xff0c;换cook…

【JS篇之】异常

前言&#xff1a;在代码编写过程中&#xff0c;最常遇到的就是程序异常。其实异常并非坏事&#xff0c;它可以让开发人员及时发现、定位到错误&#xff0c;提醒我们做正确的事情&#xff0c;甚至在某些时候&#xff0c;我们还会手动抛出异常。 1.异常的分类 在JS中&#xff0…

LinkedList与链表

文章目录 ArrayList的缺陷链表链表的概念及结构链表的实现 LinkedList的使用什么是LinkedListLinkedList具体使用 ArrayList和LinkedList的区别 ArrayList的缺陷 通过源码知道&#xff0c;ArrayList底层使用数组来存储元素 由于其底层是一段连续空间&#xff0c;当在ArrayList任…

uniApp+Vue3+vite+Element UI或者Element Plus开发学习,使用vite构建管理项目,HBuilderX做为开发者工具

我们通常给小程序或者app开发后台时&#xff0c;不可避免的要用到可视化的数据管理后台&#xff0c;而vue和Element是我们目前比较主流的开发管理后台的主流搭配。所以今天石头哥就带大家来一起学习下vue3和Element plus的开发。 准备工作 1&#xff0c;下载HBuilderX 开发者…

【webrtc】MessageHandler 8: 基于线程的消息处理:处理音频输入输出断开

m98代码,看起来m114 去掉了MessageHandler :音频的录制和播放 都使用了on message,但只是用来通知并处理流的断开的。AAudioRecorder AAudioRecorder 处理流断开 OnErrorCallback :有可能 错误回调是别处来的,是其他线程, 但是这个错误的处理要再自己的线程执行: 音频播…

Go中为什么不建议用锁?

Go语言中是不建议用锁&#xff0c;而是用通道Channel来代替(不要通过共享内存来通信&#xff0c;而通过通信来共享内存)&#xff0c;当然锁也是可以用&#xff0c;锁是防止同一时刻多个goroutine操作同一个资源&#xff1b; GO语言中&#xff0c;要传递某个数据给另一个gorout…

JavaScript原型链深度剖析

目录 前言 一、原型链 1.原型链的主要组成 原型&#xff08;Prototype&#xff09; 构造函数&#xff08;Constructor&#xff09; 实例&#xff08;Instance&#xff09; 2.原型链的工作原理 前言 在JavaScript的世界中&#xff0c;原型链&#xff08;Prototype Chain&…

R语言的学习——day1

将数据框中某一列数据改成行名 代码 结果

.net core ef 连表查询

Information和TypeInfo连表查询 类似&#xff1a; select st.Title1,si.* from [Star_Information] si left join Star_TypeInfo st on si.typeId2st.id 先在EfCoreDbContext.cs配置 protected override void OnModelCreating(ModelBuilder builder){base.OnModelCreating(b…

基于SSM的文物管理系统(含源码+sql+视频导入教程+文档+PPT)

&#x1f449;文末查看项目功能视频演示获取源码sql脚本视频导入教程视频 1 、功能描述 基于SSM的文物管理系统拥有俩种角色 管理员&#xff1a;个人信息管理、用户管理、分类管理、文物信息管理、文物外借管理、文物维修管理、留言板管理等 用户&#xff1a;登录注册、分类…

[华为OD] C卷 服务器cpu交换 现有两组服务器QA和B,每组有多个算力不同的CPU 100

题目&#xff1a; 现有两组服务器QA和B,每组有多个算力不同的CPU,其中A[i]是A组第i个CPU的运算能 力&#xff0c;B[i]是B组第i个CPU的运算能力。一组服务器的总算力是各CPU的算力之和。 为了让两组服务器的算力相等&#xff0c;允许从每组各选出一个CPU进行一次交换。 求两…

Linux 权限的简单讲解

1、前言 当我们分别使用 touch、mkdir 命令创建一名为 test1 的文件和名为 test2 的目录&#xff0c;发现其中有些参数不一样&#xff0c;本文就来给大家来剖析一下。 2、 参数讲解 我们可以通过切片分为下面几个区域&#xff0c;本文就只简单讲解文件类型、权限、所属用户、所…

CGAL 网格热力图

文章目录 一、简介二、实现代码三、实现效果参考资料一、简介 这里实现一个很有趣的功能,生成网格热力图,思路其实很简单:通过指定一个点,计算网格其他点到指定点的测地线距离,以此来为每个网格顶点进行赋色即可。 二、实现代码 //CGAL #include <CGAL/Simple_cartesi…

用HTML5实现播放gif文件

用HTML5实现播放gif文件 在HTML5中&#xff0c;你可以使用<img>标签来播放GIF文件。GIF文件本质上是一种图像格式&#xff0c;它支持动画效果&#xff0c;因此当在网页上加载时&#xff0c;它会自动播放动画。先看一个简单的示例&#xff1a; <!DOCTYPE html> &l…

Elasticsearch:探索 11 种流行的机器学习算法

作者&#xff1a;来自 Elastic Elastic Platform Team 过去几年中&#xff0c;机器学习&#xff08;ML&#xff09;已经悄然成为我们日常生活中不可或缺的一部分。它影响着从购物网站和流媒体网站上的个性化推荐&#xff0c;到保护我们的收件箱免受我们每天收到的大量垃圾邮件的…

2024年第二十六届“华东杯”(B题)大学生数学建模挑战赛|数学建模完整代码+建模过程全解全析

当大家面临着复杂的数学建模问题时&#xff0c;你是否曾经感到茫然无措&#xff1f;作为2022年美国大学生数学建模比赛的O奖得主&#xff0c;我为大家提供了一套优秀的解题思路&#xff0c;让你轻松应对各种难题。 让我们来看看华东杯 (B题&#xff09;&#xff01; 第一个问题…

神经网络与深度学习(四)--自然语言处理NLP

这里写目录标题 1.序列模型2.数据预处理2.1特征编码2.2文本处理 3.文本预处理与词嵌入3.1文本预处理3.2文本嵌入 3.RNN模型3.1RNN概要3.2RNN误差反传 4.门控循环单元&#xff08;GRU&#xff09;4.1GRU基本结构 5.长短期记忆网络 (LSTM) 1.序列模型 分类问题与预测问题 图像分…

java版本共存与fastjson反序列化rmi服务器的搭建

文章目录 java 8下载远程加载类工具编译工具mvn多版本共存配置mvn编译marshalsec编译rce文件利用marshalsec加载远程RCE类 java 8下载 链接&#xff1a;https://pan.baidu.com/s/1B8U9v8QAe4Vc67Q84_nqcg?pwd0000 提取码&#xff1a;0000 远程加载类工具 https://github.co…