Windows 编程教程中未解析的外部符号__RTC_*

Unresolved external symbols __RTC_* in Windows programming tutorial

本文关键字:符号 外部 RTC 教程 编程 Windows      更新时间:2023-10-16

使用Visual Studio Express 2010,我创建了一个Windows项目,选项为Windows Application和Empty Project。然后,我尝试了MSDN Windows教程中的以下代码片段:

#include <windows.h>
#include <shobjidl.h> 
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, PWSTR pCmdLine, int nCmdShow)
{
    HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | 
        COINIT_DISABLE_OLE1DDE);
    if (SUCCEEDED(hr))
    {
        IFileOpenDialog *pFileOpen;
        // Create the FileOpenDialog object.
        hr = CoCreateInstance(CLSID_FileOpenDialog, NULL, CLSCTX_ALL, 
                IID_IFileOpenDialog, reinterpret_cast<void**>(&pFileOpen));
        if (SUCCEEDED(hr))
        {
            // Show the Open dialog box.
            hr = pFileOpen->Show(NULL);
            // Get the file name from the dialog box.
            if (SUCCEEDED(hr))
            {
                IShellItem *pItem;
                hr = pFileOpen->GetResult(&pItem);
                if (SUCCEEDED(hr))
                {
                    PWSTR pszFilePath;
                    hr = pItem->GetDisplayName(SIGDN_FILESYSPATH, &pszFilePath);
                    // Display the file name to the user.
                    if (SUCCEEDED(hr))
                    {
                        MessageBox(NULL, pszFilePath, L"File Path", MB_OK);
                        CoTaskMemFree(pszFilePath);
                    }
                    pItem->Release();
                }
            }
            pFileOpen->Release();
        }
        CoUninitialize();
    }
    return 0;
}

我收到以下错误:

1>------ Rebuild All started: Project: Test05, Configuration: Debug Win32 ------
1>  Test05.cpp
1>Test05.obj : error LNK2019: unresolved external symbol @_RTC_CheckStackVars@8 
referenced in function _wWinMain@16
1>Test05.obj : error LNK2019: unresolved external symbol __RTC_CheckEsp referenced in 
function _wWinMain@16
1>Test05.obj : error LNK2001: unresolved external symbol __RTC_Shutdown 
1>Test05.obj : error LNK2001: unresolved external symbol __RTC_InitBase
1>LINK : error LNK2001: unresolved external symbol _wWinMainCRTStartup

这是怎么回事?最好的我能说出与wWinMain有关的东西,但它是直接从网站上复制的。

对我来说,编译器似乎比学习编程更麻烦。在尝试了其他一些(主要是代码块)后,我决定使用 Visual C++,但由于 Visual C++ 似乎拥有最多的支持(或至少是大多数用户),我认为这总比从不去任何地方要好,因为它们对初学者来说都是如此不直观。

使用"基本运行时检查"时会添加_RTC_xxx符号;要禁用它们,您可以转到项目属性,并将"配置属性>C/C++>所有选项>基本运行时检查"选项设置为"默认"。 但是,正如其他答案中提到的,看起来您在 C 运行时库中存在不匹配。

看起来您正在链接与编译所针对的不同运行时库版本。

请确保您只安装了一个版本的 Visual Studio 和路径。

如果您有多个版本,请尝试暂时重命名其他 Visual Studio 安装的根目录,看看这是否会导致任何影响。

我会

从此处的链接下载完整的代码示例,而不是复制和粘贴您链接到的代码片段。项目文件中可能存在未显示的重要编译器/链接器设置。该示例是一个 VS 2008 解决方案,但我能够将其升级到 2010 解决方案并生成它。但是,当我尝试在VS 2008中构建它时,它给了我"致命的链接器错误:找不到'kernel32.lib'"。

相关文章: