MFC Link problem

本文详细解释了如何在使用MFC和CRT库时确保MFC库在CRT库之前正确链接的方法,通过创建特定的头文件来实现不同配置下的库选择。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

nafxcw.lib    for MFC Static  Link Library

Use of MFC in a Shared  DLL : _AFXDLL  in "preprocessor definitions" list defined

When Using both CRT and MFC libraries together you need to be careful. In such cases its important for MFC libraries to get linked before CRT libraries.

If you are using MFC, you need to link libc.lib before msvcrt.lib. You can do this by explicitely setting linker option.

please go through this link... http://support.microsoft.com/kb/148652
problem while linking CRT and MFC together

Great!!! Thanks alot sach!!

The solution I used was as per the link and creating a new header file, ForceLib.h. The file looks like this:
Code:
#ifndef _AFX_NOFORCE_LIBS

/////////////////////////////////////////////////////////////////////////////
// Win32 libraries

#ifndef _AFXDLL
    #ifndef _UNICODE
        #ifdef _DEBUG
            #pragma comment(lib, "nafxcwd.lib")
        #else
            #pragma comment(lib, "nafxcw.lib")
        #endif
    #else
        #ifdef _DEBUG
            #pragma comment(lib, "uafxcwd.lib")
        #else
            #pragma comment(lib, "uafxcw.lib")
        #endif
    #endif
#else
    #ifndef _UNICODE
        #ifdef _DEBUG
            #pragma comment(lib, "mfc71d.lib")
            #pragma comment(lib, "mfcs71d.lib")
        #else
            #pragma comment(lib, "mfc71.lib")
            #pragma comment(lib, "mfcs71.lib")
        #endif
    #else
        #ifdef _DEBUG
            #pragma comment(lib, "mfc71ud.lib")
            #pragma comment(lib, "mfcs71ud.lib")
        #else
            #pragma comment(lib, "mfc71u.lib")
            #pragma comment(lib, "mfcs71u.lib")
        #endif
    #endif
#endif

#ifdef _DLL
    #if !defined(_AFX_NO_DEBUG_CRT) && defined(_DEBUG)
        #pragma comment(lib, "msvcrtd.lib")
    #else
        #pragma comment(lib, "msvcrt.lib")
    #endif
#else
#ifdef _MT
    #if !defined(_AFX_NO_DEBUG_CRT) && defined(_DEBUG)
        #pragma comment(lib, "libcmtd.lib")
    #else
        #pragma comment(lib, "libcmt.lib")
    #endif
#else
    #if !defined(_AFX_NO_DEBUG_CRT) && defined(_DEBUG)
        #pragma comment(lib, "libcd.lib")
    #else
        #pragma comment(lib, "libc.lib")
    #endif
#endif
#endif

#pragma comment(lib, "kernel32.lib")
#pragma comment(lib, "user32.lib")
#pragma comment(lib, "gdi32.lib")
#pragma comment(lib, "msimg32.lib")
#pragma comment(lib, "comdlg32.lib")
#pragma comment(lib, "winspool.lib")
#pragma comment(lib, "advapi32.lib")
#pragma comment(lib, "shell32.lib")
#pragma comment(lib, "comctl32.lib")
#pragma comment(lib, "shlwapi.lib")

// force inclusion of NOLIB.OBJ for /disallowlib directives
#pragma comment(linker, "/include:__afxForceEXCLUDE")

// force inclusion of DLLMODUL.OBJ for _USRDLL
#ifdef _USRDLL
#pragma comment(linker, "/include:__afxForceUSRDLL")
#endif

// force inclusion of STDAFX.OBJ for precompiled types
#ifdef _AFXDLL
#pragma comment(linker, "/include:__afxForceSTDAFX")
#endif

#endif //!_AFX_NOFORCE_LIBS

raw_file.c "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\bin\HostX86\x64\link.exe" /nologo /INCREMENTAL:NO /LTCG /DLL /MANIFEST:EMBED,ID=2 /MANIFESTUAC:NO /LIBPATH:D:\anaconda3\libs /LIBPATH:D:\anaconda3 /LIBPATH:D:\anaconda3\PCbuild\amd64 "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\ATLMFC\lib\x64" "/LIBPATH:C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.44.35207\lib\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\lib\um\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\lib\10.0.26100.0\ucrt\x64" "/LIBPATH:C:\Program Files (x86)\Windows Kits\10\\lib\10.0.26100.0\\um\x64" c.lib /EXPORT:PyInit__hdf5maker build\temp.win-amd64-cpython-313\Release\src\hdf5maker.obj build\temp.win-amd64-cpython-313\Release\src\raw_file.obj /OUT:build\lib.win-amd64-cpython-313\_hdf5maker.cp313-win_amd64.pyd /IMPLIB:build\temp.win-amd64-cpython-313\Release\src\_hdf5maker.cp313-win_amd64.lib LINK : fatal error LNK1181: 无法打开输入文件“c.lib” error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2022\\BuildTools\\VC\\Tools\\MSVC\\14.44.35207\\bin\\HostX86\\x64\\link.exe' failed with exit code 1181 [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for hdf5maker Running setup.py clean for hdf5maker Failed to build hdf5maker error: failed-wheel-build-for-install × Failed to build installable wheels for some pyproject.toml based projects ╰─> hdf5maker
最新发布
08-08
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值