一个单例模式中使用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 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.

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

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

【webrtc】MessageHandler 6: 基于线程的消息处理:StunRequest实现包发送和超时重传

G:\CDN\rtcCli\m98\src\p2p\base\stun_request.cc使用OnMessage 实现包的发送和包的超时重传StunRequest 一个StunRequest 代表是一个独立的请求的发送STUN消息 要不是发送前构造好的,要不就是按照需要构建的使用StunRequestManager: 每一个STUNRequest 携带一个交互id 写入m…

windows11安装nginx

1.解压nginx安装包到没有中文的目录 2.双击运行nginx.exe 3.任务管理器查看是否有nginx进程 4.任务管理器->性能->资源监视器 5.网络->侦听端口&#xff0c;查看nginx侦听的端口&#xff0c;这里是90端口

nginx下载安装配置(含ssl)

下载安装环节 wget https://nginx.org/download/nginx-1.24.0.tar.gz tar -zxvf xxx.tar.gz yum -y install pcre-devel openssl openssl-devel ./configure --prefix/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream make & make i…

SpringCloud 学习笔记 —— 六、Ribbon:负载均衡(基于客户端)

SpringCloud 学习笔记 —— 一、背景-CSDN博客 SpringCloud 学习笔记 —— 二、微服务与微服务架构-CSDN博客 SpringCloud 学习笔记 —— 三、SpringCloud 入门概述-CSDN博客 SpringCloud 学习笔记 —— 四、SpringCloud Rest 学习环境搭建&#xff1a;服务提供者-CSDN博客 …

界面组件DevExpress中文教程 - 如何在Node.js应用中创建报表?

DevExpress Reporting是.NET Framework下功能完善的报表平台&#xff0c;它附带了易于使用的Visual Studio报表设计器和丰富的报表控件集&#xff0c;包括数据透视表、图表&#xff0c;因此您可以构建无与伦比、信息清晰的报表。 获取DevExpress Reporting最新正式版下载(Q技术…

Mybatis-Plus扩展接口InnerInterceptor

InnerInterceptor 接口就是 MyBatis-Plus 提供的一个拦截器接口&#xff0c;用于实现一些常用的 SQL 处理逻辑&#xff0c;处理 MyBatis-Plus 的特定功能,例如PaginationInnerInterceptor、OptimisticLockerInnerInterceptor 等,都实现了 InnerInterceptor 接口&#xff0c;并添…

透视天气:数据可视化的新视角

数据可视化在天气方面能够为我们带来极大的帮助。天气是人类生活中一个重要的因素&#xff0c;对于农业、交通、航空、能源等各个领域都有着重要的影响。而数据可视化技术通过将复杂的天气数据转化为直观、易懂的图表、图像或地图等形式&#xff0c;为我们提供了更深入、更全面…

数据赋能(73)——数据要素:特征

生产要素中的数据要素具有一系列基本特征&#xff0c;这些特征使得数据在现代经济活动中发挥着越来越重要的作用。数据要素的主要特征如下图所示。 数据已经成为关键的生产要素&#xff0c;数据要素的基本特征可以概括为&#xff1a;虚拟性、非消耗性、非稀缺性、非均质性、排他…

移植USB RTL8723DU WIFI无线驱动给RK3588

wifi 通过dmesg发现可以识别到设备为无线网卡&#xff0c;并驱动蓝牙&#xff0c;但是在ifconfig中没有找到对应的wlan0。 推断有可能是内核里面没有针对8723du wifi的驱动。所以需要查询当前的5.10内核是否包含8723du的驱动。到https://linux-hardware.org/ 上查看。 并结合…

使用RTSP将笔记本摄像头的视频流推到开发板

一、在Windows端安装ffmpeg 1. 下载ffmpeg:下载ffmpeg 解压ffmpeg-master-latest-win64-gpl.zip bin 目录下是 dll 动态库 , 以及 可执行文件 ;将 3 33 个可执行文件拷贝到 " C:\Windows " 目录下 ,将所有的 " .dll " 动态库拷贝到 " C:\Windows\Sy…

linus下Anaconda创建虚拟环境pytorch

一、虚拟环境 1.创建 输入下面命令 conda create -n env_name python3.8 输入y 2.激活环境 输入 conda activate env_name 二、一些常用的命令 在Linux的控制平台 切换到当前的文件夹 cd /根目录/次目录 查看conda目录 conda list 查看pip目录 pip list查看历史命…

Springboot+Vue项目-基于Java+MySQL的教学资料管理系统(附源码+演示视频+LW)

大家好&#xff01;我是程序猿老A&#xff0c;感谢您阅读本文&#xff0c;欢迎一键三连哦。 &#x1f49e;当前专栏&#xff1a;Java毕业设计 精彩专栏推荐&#x1f447;&#x1f3fb;&#x1f447;&#x1f3fb;&#x1f447;&#x1f3fb; &#x1f380; Python毕业设计 &…

[游戏陪玩系统] 陪玩软件APP小程序H5游戏陪玩成品软件源码-线上线下可爆改家政,整理师等功能

简介 随着电竞行业的快速发展&#xff0c;电竞陪玩APP正在逐渐成为用户在休闲娱乐时的首选。为了吸引用户和提高用户体验&#xff0c;电竞陪玩APP开发需要定制一些特色功能&#xff0c;并通过合适的盈利模式来获得收益。本文将为您介绍电竞陪玩APP开发需要定制的特色功能以及常…

AI图书推荐:将 ChatGPT和Excel融合倍增工作效率

《将 ChatGPT和Excel融合倍增工作效率》&#xff08; Hands-on ChatGPT in Excel. Enhance Your Excel Workbooks&#xff09;由Mitja Martini撰写&#xff0c;旨在教授读者如何将ChatGPT与Excel结合使用&#xff0c;以提升工作效率和创造AI增强的Excel工具。它还提供了Excel中…

2024年Docker常用操作快速查询手册

目录 一、Linux系统上 Docker安装流程&#xff08;以ubuntu为例&#xff09; 一、卸载所有冲突的软件包 二、设置Docker的apt存储库&#xff08;这里使用的是阿里云软件源&#xff09; 三、直接安装最新版本的Docker 三、安装指定版本的Docker 四、验证Docker是否安装成功…

06_Flutter自定义锚点分类列表

06_Flutter自定义锚点分类列表 这样的效果&#xff0c;大家在一些商超应用里&#xff0c;应该也看到过。接下来咱们就用Flutter一步一步的来实现。 一.自定义属性抽取 categoryWidth: 左侧边栏的宽度&#xff0c;右侧区域的宽度填充剩余空间即可。itemCount: 总共有多少个分类…

Centos 系列 安装ArchR

Analyzing single-cell regulatory chromatin in R. • ArchRhttps://www.archrproject.com/ ArchR is a scalable software package for integrative single-cell chromatin accessibility analysis 一、Installation of ArchR &#xff08;Ideal&#xff09; ArchR is desig…

四川古力未来科技抖音小店安全:守护您的网购体验

在互联网购物日益普及的今天&#xff0c;四川古力未来科技抖音小店以其独特的魅力和安全保障措施&#xff0c;成为越来越多消费者信赖的购物平台。本文将为您详细解读四川古力未来科技抖音小店的安全保障措施&#xff0c;让您在享受便捷购物的同时&#xff0c;也能安心、放心。…

【简单讲解下FastStone Capture】

&#x1f3a5;博主&#xff1a;程序员不想YY啊 &#x1f4ab;CSDN优质创作者&#xff0c;CSDN实力新星&#xff0c;CSDN博客专家 &#x1f917;点赞&#x1f388;收藏⭐再看&#x1f4ab;养成习惯 ✨希望本文对您有所裨益&#xff0c;如有不足之处&#xff0c;欢迎在评论区提出…

首页最新 多IP浏览器防关联:如何配置多个独立且稳定的IP地址?

在互联网时代&#xff0c;IP地址的重要性不言而喻。然而&#xff0c;IP关联问题却成为一项令人担忧的隐私和安全挑战。针对这个问题&#xff0c;多IP浏览器是一种解决方案&#xff0c;可以帮助用户单独配置多个独立且稳定的IP地址&#xff0c;有效地防止IP关联。 一、IP关联是…