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

news2025/1/10 23:48:59

使用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 once
    
    extern "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.coloradmin.cn/o/1636050.html

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

相关文章

【机器学习】视觉基础模型的三维意识:前沿探索与局限

视觉基础模型的三维意识&#xff1a;前沿探索与局限 一、引言二、视觉基础模型的三维意识三、当前模型的局限性四、实验与结果五、总结与展望 大规模预训练的进展已经产生了具有强大能力的视觉基础模型。最近的模型不仅可以推广到任意图像的训练任务&#xff0c;而且它们的中间…

spring boot 基础案例【3】构建RESTful API与单元测试

教程1 案例教程 案例仓库 在线编程 教程2 基础教程 教程仓库 在线编程 本案例所在的仓库 本案例所在的文档 进入正文 1.文件目录 1. Chapter21Application.java 地址&#xff1a;chapter2-1/src/main/java/com/didispace/chapter21/Chapter21Application.java package com.d…

CSS @keyframes 动画:颜色变化、背景旋转与放大缩小

在CSS中&#xff0c;keyframes 是一个强大的工具&#xff0c;它允许我们创建复杂的动画效果。今天&#xff0c;我们将一起探索如何使用 keyframes 来实现颜色变化、背景旋转以及放大缩小的动画效果。 动画会在 2 秒内循环播放&#xff0c;并在不同的时间点改变盒子的背景颜色和…

【JVM】简述类加载器及双亲委派机制

双亲委派模型&#xff0c;是加载class文件的一种机制。在介绍双亲委派模型之前&#xff0c;我需要先介绍几种类加载器&#xff08;Class Loader&#xff09;。 1&#xff0c;类加载器 Bootstrap&#xff0c;加载lib/rt.jar&#xff0c;charset.jar等中的核心类&#xff0c;由…

VS code 同步odata服务

在做UI5得开发过程中&#xff0c;经常会出现odata需要更新 那么已经加载过得项目如何去跟新odata服务呢 可以通过如下步骤 1.右键打开应用信息 2.找到manage service models 3.点击编辑 4.选中 刷新并保存

前端发起网络请求的几种常见方式(XMLHttpRequest、FetchApi、jQueryAjax、Axios)

摘要 前端发起网络请求的几种常见方式包括&#xff1a; XMLHttpRequest (XHR)&#xff1a; 这是最传统和最常见的方式之一。它允许客户端与服务器进行异步通信。XHR API 提供了一个在后台发送 HTTP 请求和接收响应的机制&#xff0c;使得页面能够在不刷新的情况下更新部分内容…

【YOLOv9改进[Conv]】使用基于Haar的小波变换Down_wt处理替换模型结构中的Conv和ADown 实践

目录 一 基于Haar的小波变换 二 使用基于Haar的小波变换Down_wt处理替换模型结构中的Conv和ADown 实践 1 整体修改 2 配置文件 3 训练 三 报错处理 一 基于Haar的小波变换 Haar小波是最简单的小波形式之一&#xff0c;具有易于计算和实现的优点。使用二维离散小波变换&a…

TCP重传,滑动窗口,流量控制,拥塞控制

TCP重传&#xff0c;滑动窗口&#xff0c;流量控制&#xff0c;拥塞控制 TCP重传机制&#xff1a; 超时重传快速重传SACKD-SACK 通过序列号与确认应答判断是否要重传 超时重传&#xff1a; 超过指定时间没有收到确认应答报文&#xff0c;就会重发该数据 触发超时重传的情况…

k8s 资源组版本支持列表

1 kubernetes的资源注册表 kube-apiserver组件启动后的第一件事情是将Kubernetes所支持的资源注册到Scheme资源注册表中,这样后面启动的逻辑才能够从Scheme资源注册表中拿到资源信息并启动和运行API服务。 kube-apiserver资源注册分为两步:第1步,初始化Scheme资源注册表;…

【论文笔记】Training language models to follow instructions with human feedback A部分

Training language models to follow instructions with human feedback A 部分 回顾一下第一代 GPT-1 &#xff1a; 设计思路是 “海量无标记文本进行无监督预训练少量有标签文本有监督微调” 范式&#xff1b;模型架构是基于 Transformer 的叠加解码器&#xff08;掩码自注意…

【百度Apollo】探索自动驾驶:百度Apollo视觉感知模块的实践与创新

&#x1f3ac; 鸽芷咕&#xff1a;个人主页 &#x1f525; 个人专栏: 《linux深造日志》《粉丝福利》 ⛺️生活的理想&#xff0c;就是为了理想的生活! 文章目录 引入一、百度Apollo视觉感知模块概述二、启动感知模块步骤一&#xff1a;进入 Docker 环境并启动 Dreamview步骤二…

请编写函数fun,该函数的功能是:统计各年龄段的人数。N个年龄通过调用随机函数获得,并放在主函数的age数组中;

本文收录于专栏:算法之翼 https://blog.csdn.net/weixin_52908342/category_10943144.html 订阅后本专栏全部文章可见。 本文含有题目的题干、解题思路、解题思路、解题代码、代码解析。本文分别包含C语言、C++、Java、Python四种语言的解法完整代码和详细的解析。 题干 请编…

我开始接单/兼职/搞副业/建设个人社区,为自己谋后路了。

我开始接单/兼职/搞副业/建设个人社区&#xff0c;为自己谋后路了。 简述 大家好&#xff0c;我是小荣&#xff0c;一个前端开发程序员。我最近开始在业余时间接私单了&#xff0c;也在想一些能够带来成长&#xff0c;收入的副业&#xff0c;主要也是为了自己谋后路&#xff…

ctfshow——SQL注入

文章目录 SQL注入基本流程普通SQL注入布尔盲注时间盲注报错注入——extractvalue()报错注入——updataxml()Sqlmap的用法 web 171——正常联合查询web 172——查看源代码、联合查询web 173——查看源代码、联合查询web 174——布尔盲注web 176web 177——过滤空格web 178——过…

【算法刷题 | 贪心算法09】4.30(单调递增的数字)

文章目录 16.单调递增的数字16.1题目16.2解法&#xff1a;贪心16.2.1贪心思路16.2.2代码实现 16.单调递增的数字 16.1题目 当且仅当每个相邻位数上的数字 x 和 y 满足 x < y 时&#xff0c;我们称这个整数是单调递增的。 给定一个整数 n &#xff0c;返回 小于或等于 n 的…

jenkins转载文本

基于Docker容器DevOps应用方案 企业业务代码发布系统 一、企业业务代码发布方式 1.1 传统方式 以物理机或虚拟机为颗粒度部署部署环境比较复杂&#xff0c;需要有先进的自动化运维手段出现问题后重新部署成本大&#xff0c;一般采用集群方式部署部署后以静态方式展现 1.2 容…

ubuntu部署sonar与windows下使用sonar-scanner

ubuntu部署sonar与windows下使用sonar-scanner sonar部署java安装mysql安装配置sonarqube 插件安装sonar-scanner使用简单使用 sonar部署 使用的是sonarqube-7.5&#xff0c;支持的java环境是jdk8&#xff0c;且MySQL版本 >5.6 && <8.0 java安装 打开终端&…

【初识Redis】

初识Redis Redis&#xff08;Remote Dictionary Server&#xff09;是一个开源的内存数据库&#xff0c;它提供了一个高性能的键值存储系统&#xff0c;并且支持多种数据结构&#xff0c;包括字符串、哈希、列表、集合和有序集合等。Redis的特点包括&#xff1a; 内存存储&…

Apache DolphinScheduler支持Flink吗?

随着大数据技术的快速发展&#xff0c;很多企业开始将Flink引入到生产环境中&#xff0c;以满足日益复杂的数据处理需求。而作为一款企业级的数据调度平台&#xff0c;Apache DolphinScheduler也跟上了时代步伐&#xff0c;推出了对Flink任务类型的支持。 Flink是一个开源的分…

2023年蓝桥杯C++A组第三题:更小的数(双指针解法)

题目描述 小蓝有一个长度均为 n 且仅由数字字符 0 ∼ 9 组成的字符串&#xff0c;下标从 0 到 n − 1&#xff0c;你可以将其视作是一个具有 n 位的十进制数字 num&#xff0c;小蓝可以从 num 中选出一段连续的子串并将子串进行反转&#xff0c;最多反转一次。小蓝想要将选出的…