__osplatform 已经在 atlmincrt.lib(atlinit.obj) 中定义解决方法

解决LIBCMT.lib错误LNK2005
本文解决了一个常见的编译错误:LIBCMT.lib中的__osplatform被重复定义的问题。通过在项目属性页的配置属性—链接器—输入—忽略指定库中加入atlmincrt.lib来解决此问题。

LIBCMT.lib(crt0dat.obj) : error LNK2005: __osplatform 已经在 atlmincrt.lib(atlinit.obj) 中定义 (vc.net)

 

解决方法:打开项目属性页,在 配置属性--链接器--输入--忽略指定库 里面输入atlmincrt.lib

 

http://www.d1778.com

System.EntryPointNotFoundException HResult=0x80131523 Message=Unable to find an entry point named 'TF_GetHandleShapeAndType' in DLL 'tensorflow'. Source=Tensorflow.Binding StackTrace: 在 Tensorflow.c_api.TF_GetHandleShapeAndType(SafeGraphHandle c_graph, TF_Output output) 在 Tensorflow.ops.get_resource_handle_data(Tensor graph_op) 在 Tensorflow.Operations.handle_data_util.get_resource_handle_data(Tensor graph_op) 在 Tensorflow.Eager.backprop_util._DTypeFromTensor(Tensor tensor) 在 Tensorflow.Eager.backprop_util.IsTrainable(Tensor tensor) 在 Tensorflow.Functions.TapeGradientFunctions.<>c.<.ctor>b__16_0(Tensor t) 在 System.Linq.Enumerable.WhereEnumerableIterator`1.GetCount(Boolean onlyIfCheap) 在 Tensorflow.Functions.TapeGradientFunctions..ctor(FuncGraph func_graph, Boolean need_gradients_for_jvps) 在 Tensorflow.Functions.DelayedRewriteGradientFunctions..ctor(FuncGraph func_graph, Dictionary`2 attrs) 在 Tensorflow.Functions.ConcreteFunction._set_infer_function() 在 Tensorflow.Functions.ConcreteFunction..ctor(Func`2 func, TF_DataType dtype) 在 Tensorflow.FlatMapDataset..ctor(IDatasetV2 input_dataset, Func`2 map_func) 在 Tensorflow.DatasetV2.flat_map(Func`2 map_func) 在 Tensorflow.Keras.Engine.DataAdapters.TensorLikeDataAdapter..ctor(DataAdapterArgs args) 在 Tensorflow.Keras.Engine.DataAdapters.DataHandler..ctor(DataHandlerArgs args) 在 Tensorflow.Keras.Engine.Model.evaluate(NDArray x, NDArray y, Int32 batch_size, Int32 verbose, NDArray sample_weight, Int32 steps, Int32 max_queue_size, Int32 workers, Boolean use_multiprocessing, Boolean return_dict, Boolean is_val) 在 Keras.NET_Prediction_main_program.Program.Main() 在 D:\编程软件系列\VS2022社区版\文件\Keras.NET Prediction main program\Program.cs 中: 第 254 行
最新发布
11-26
#ifndef _SYSTEM_DETECTOR_H_ #define _SYSTEM_DETECTOR_H_ #ifdef _WIN32 //#ifndef _WIN32_WINNT_WIN7 //#define _WIN32_WINNT_WIN7 0x0601 //#endif // !_WIN32_WINNT_WIN7 // 检查编译环境SDK是否支持 //#if (_WIN32_WINNT < _WIN32_WINNT_WIN7) //#error "This application requires Windows SDK 7.0 or higher. Please update your Windows SDK." //#error "此应用程序需要 Windows SDK 7.0 或更高版本进行编译." //#endif #define _CRT_SECURE_NO_WARNINGS #define NO_WARN_MBCS_MFC_DEPRECATION #include <SDKDDKVer.h> #include <afxwin.h> //#include <versionhelpers.h> namespace D2DRENDER { // 枚举操作系统平台类型 enum class OSPlatform { Windows7, Windows8, Windows8_1, Windows10, Windows11, Unknown }; // 系统检测类 class CSystemDetector { public: CSystemDetector(); OSPlatform m_OSPlatform; int m_nCurrentBuild; }; extern CSystemDetector g_SystemDetector; //以下函数都是读取, 不用加锁, 线程安全 //判断是Windows 11 bool IsWin11(); // 判断是Windows 10 bool IsWin10(); // 判断是Windows 8.1 bool IsWin8_1(); // 判断是否Windows 8 bool IsWin8(); // 判断是否Windows 7 bool IsWin7(); // 判断是否win8.1 或以上系统 bool IsWin8_1orGreater(); } #endif // !_WIN32 #endif // !_SYSTEM_DETECTOR_H_ #include "SystemDetector.h" #pragma comment(linker, "/DELAYLOAD:dcomp.dll")//延迟加载dcomp.dll, 运行时才加载,配合LoadLibrary就能知道当前系统有没有dcomp.dll了 D2DRENDER::CSystemDetector g_SystemDetector; D2DRENDER::CSystemDetector::CSystemDetector() :m_OSPlatform(OSPlatform::Unknown), m_nCurrentBuild(0) { // 检测当前操作系统并返回平台类型 HKEY hKey; LONG lResult = RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, &hKey); if (lResult == ERROR_SUCCESS) { DWORD dwType; DWORD dwSize = 16; char szCurrentBuild[16] = { 0 }; RegQueryValueEx(hKey, "CurrentBuild", NULL, &dwType, (LPBYTE)szCurrentBuild, &dwSize); RegCloseKey(hKey); m_nCurrentBuild = atoi(szCurrentBuild); } if (m_nCurrentBuild >= 7600 && m_nCurrentBuild < 9200) { m_OSPlatform = OSPlatform::Windows7; } else if (m_nCurrentBuild >= 9200 && m_nCurrentBuild < 9600) { m_OSPlatform = OSPlatform::Windows8; } else if (m_nCurrentBuild >= 9600 && m_nCurrentBuild < 10240) { m_OSPlatform = OSPlatform::Windows8_1; } else if (m_nCurrentBuild >= 10240 && m_nCurrentBuild < 22000) { m_OSPlatform = OSPlatform::Windows10; } else if (m_nCurrentBuild >= 22000) { m_OSPlatform = OSPlatform::Windows11; } else { m_OSPlatform = OSPlatform::Unknown;//win7 以下都是未知系统 } } //判断是Windows 11 bool D2DRENDER::IsWin11() { return g_SystemDetector.m_OSPlatform == OSPlatform::Windows11; } // 判断是Windows 10 bool D2DRENDER::IsWin10() { return g_SystemDetector.m_OSPlatform == OSPlatform::Windows10; } // 判断是Windows 8.1 bool D2DRENDER::IsWin8_1() { return g_SystemDetector.m_OSPlatform == OSPlatform::Windows8_1; } // 判断是否Windows 8 bool D2DRENDER::IsWin8() { return g_SystemDetector.m_OSPlatform == OSPlatform::Windows8; } // 判断是否Windows 7 bool D2DRENDER::IsWin7() { return g_SystemDetector.m_OSPlatform == OSPlatform::Windows7; } // 判断是否win8.1 或以上系统 bool D2DRENDER::IsWin8_1orGreater() { return g_SystemDetector.m_nCurrentBuild >= 9600; }
08-11
// 枚举操作系统平台类型 enum class OSPlatform { Windows7, Windows8, Windows8_1, Windows10, Windows11, Unknown }; // 匹配 dcomp.h 中的 DCompositionCreateDevice 函数原型 typedef HRESULT(WINAPI* funcDCompositionCreateDevice)( IDXGIDevice* dxgiDevice, REFIID riid, void** ppv ); // 匹配 dcomp.h 中的 DCompositionCreateDevice2 函数原型 typedef HRESULT(WINAPI* funcDCompositionCreateDevice2)( IUnknown* renderingDevice, REFIID riid, void** ppv ); //COM接口定义 EXTERN_C CONST GUID IID_ISystemObject; struct __declspec(uuid("118DFFD4-196C-46DB-8B77-F3033D368A7C")) ISystemObject:public IUnknown { STDMETHOD_(HRESULT, QueryInterface)(REFIID riid, void** ppvObject)PURE; STDMETHOD_(ULONG, AddRef)()PURE; STDMETHOD_(ULONG, Release)()PURE; STDMETHOD_(BOOL, IsWin7)()CONST PURE; STDMETHOD_(BOOL, IsWin8)()CONST PURE; STDMETHOD_(BOOL, IsWin81orGreater)()CONST PURE; }; //COM实现: 系统检测器 class SystemDetector :public ISystemObject { public: ~SystemDetector(); STDMETHOD_(HRESULT, QueryInterface)(REFIID riid, void** ppvObject); STDMETHOD_(ULONG, AddRef)(); STDMETHOD_(ULONG, Release)(); STDMETHOD_(BOOL, IsWin7)()CONST; STDMETHOD_(BOOL, IsWin8)()CONST; STDMETHOD_(BOOL, IsWin81orGreater)()CONST; STDMETHOD_(OSPlatform, GetOSPlatform)()CONST; STDMETHOD_(int, GetCurrentBuild)()CONST; static SystemDetector& GetInstance(); private: SystemDetector();//禁止构造函数,单例模式 private: LONG m_nRefCount; OSPlatform m_OSPlatform; DWORD m_dwMajor; DWORD m_dwMinor; DWORD m_dwBuild; static std::mutex m_Mutex; static SystemDetector* m_pInstance; }; #include "SystemDetector.h" //取出RtlGetNtVersionNumbers函数头 #ifdef __cplusplus extern "C" { #endif void NTAPI RtlGetNtVersionNumbers( DWORD* lpdwMajorVersion, DWORD* lpdwMinorVersion, DWORD* lpdwBuildNumber ); #pragma comment(lib, "ntdll.lib") #ifdef __cplusplus } #endif using namespace D2DRENDER;//展开命名空间 EXTERN_C CONST GUID IID_ISystemObject = __uuidof(ISystemObject);//创建GUID SystemDetector* SystemDetector::m_pInstance = nullptr;//初始化单例指针 SystemDetector::SystemDetector() : m_nRefCount(0), m_OSPlatform(OSPlatform::Unknown), m_dwMajor(0), m_dwMinor(0), m_dwBuild(0) { // 检测当前操作系统并返回平台类型 RtlGetNtVersionNumbers(&m_dwMajor, &m_dwMinor, &m_dwBuild); m_dwBuild &= 0xfffffff; if (m_dwBuild >= 7600 && m_dwBuild < 9200) { m_OSPlatform = OSPlatform::Windows7; } else if (m_dwBuild >= 9200 && m_dwBuild < 9600) { m_OSPlatform = OSPlatform::Windows8; } else if (m_dwBuild >= 9600 && m_dwBuild < 10240) { m_OSPlatform = OSPlatform::Windows8_1; } else if (m_dwBuild >= 10240 && m_dwBuild < 22000) { m_OSPlatform = OSPlatform::Windows10; } else if (m_dwBuild >= 22000) { m_OSPlatform = OSPlatform::Windows11; } else { m_OSPlatform = OSPlatform::Unknown;//win7 以下都是未知系统 } } SystemDetector::~SystemDetector() { } SystemDetector& SystemDetector::GetInstance() { std::lock_guard<std::mutex> lock(m_Mutex);//原子等待锁,成功占用锁才继续执行 if (!m_pInstance) { m_pInstance = new SystemDetector(); } AddRef() return *m_pInstance; } __declspec(nothrow) HRESULT __stdcall SystemDetector::QueryInterface(REFIID riid, void** ppvObject) { return E_NOINTERFACE; } __declspec(nothrow) ULONG __stdcall SystemDetector::AddRef() { return ++m_nRefCount; } __declspec(nothrow) ULONG __stdcall SystemDetector::Release() { ULONG nCount = --m_nRefCount; if (nCount == 0) { delete m_pInstance; m_pInstance = nullptr; } return nCount; } 为什么Instance里面不能AddRef()
08-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值