简体   繁体   English

“LNK2019: unresolved external symbol”错误解决建议

[英]"LNK2019: unresolved external symbol" error resolution suggestions

Checked already asked questions but coudn't find a solution to this.检查已经提出的问题,但找不到解决方案。

I am trying to reproduce the example provided in https://learn.microsoft.com/en-us/uwp/api/Windows.UI.Xaml.Media.Animation.RepositionThemeAnimation?redirectedfrom=MSDN&view=winrt-22000我正在尝试重现https://learn.microsoft.com/en-us/uwp/api/Windows.UI.Xaml.Media.Animation.RepositionThemeAnimation?redirectedfrom=MSDN&view=winrt-22000中提供的示例

<Page
    x:Class="ButtonApp.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:ButtonApp"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Grid>
        <Grid.Resources>
             <!--Sets up a RepositionThemeAnimation using the FromHorizontalOffset property 
             to start the animation from the old location.--> 
            <Storyboard x:Name="PointerReleasedStoryboard">
                <RepositionThemeAnimation Storyboard.TargetName="myRectangle" FromHorizontalOffset="-400"/>
            </Storyboard>
        </Grid.Resources>

        <Rectangle x:Name="myRectangle" 
         HorizontalAlignment="Left" 
         Width="200" 
         Height="200" 
         Fill="Blue"
         PointerReleased="myRectangle_PointerReleased" 
/>
    </Grid>
</Page>

In MainPage.h I added在 MainPage.h 中我添加了

#pragma once

#include "MainPage.g.h"

namespace winrt::ButtonApp::implementation
{
    struct MainPage : MainPageT<MainPage>
    {
        MainPage();

        int32_t MyProperty();
        void MyProperty(int32_t value);
       
        void myRectangle_PointerReleased(winrt::Windows::Foundation::IInspectable const& sender, 
            winrt::Windows::UI::Xaml::Input::PointerRoutedEventArgs const& e);
    };
}

namespace winrt::ButtonApp::factory_implementation
{
    struct MainPage : MainPageT<MainPage, implementation::MainPage>
    {
    };
}

In MainPage.cpp在 MainPage.cpp 中

#include "pch.h"
#include "MainPage.h"
#include "MainPage.g.cpp"

using namespace winrt;
using namespace Windows::UI::Xaml;
using namespace Windows::UI::Xaml::Media::Animation;

namespace winrt::ButtonApp::implementation
{
    MainPage::MainPage()
    {
        InitializeComponent();
    }

    int32_t MainPage::MyProperty()
    {
        throw hresult_not_implemented();
    }

    void MainPage::MyProperty(int32_t /* value */)
    {
        throw hresult_not_implemented();
    }
}


void winrt::ButtonApp::implementation::MainPage::myRectangle_PointerReleased(winrt::Windows::Foundation::IInspectable const& sender, 
    winrt::Windows::UI::Xaml::Input::PointerRoutedEventArgs const& e)
{
    myRectangle().Margin({ 400, 0, 0, 0 });
    PointerReleasedStoryboard().Begin();
}

pch.h file: pch.h文件:

#pragma once
#include <windows.h>
#include <unknwn.h>
#include <restrictederrorinfo.h>
#include <hstring.h>
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.ApplicationModel.Activation.h>
#include <winrt/Windows.UI.Xaml.h>
#include <winrt/Windows.UI.Xaml.Controls.h>
#include <winrt/Windows.UI.Xaml.Controls.Primitives.h>
#include <winrt/Windows.UI.Xaml.Data.h>
#include <winrt/Windows.UI.Xaml.Interop.h>
#include <winrt/Windows.UI.Xaml.Markup.h>
#include <winrt/Windows.UI.Xaml.Navigation.h>
#include <winrt/Windows.UI.Xaml.Media.Animation.h>
#include <winrt/Windows.UI.Xaml.Shapes.h>

Not sure what is missing I am getting this error不确定缺少什么我收到此错误

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2019 unresolved external symbol "public: __thiscall winrt::Windows::UI::Xaml::Input::PointerEventHandler::PointerEventHandler<class <lambda_304a3567805bccbaf9da8ada06fcdf84> >(class <lambda_304a3567805bccbaf9da8ada06fcdf84>)" (??$?0V<lambda_304a3567805bccbaf9da8ada06fcdf84>@@@PointerEventHandler@Input@Xaml@UI@Windows@winrt@@QAE@V<lambda_304a3567805bccbaf9da8ada06fcdf84>@@@Z) referenced in function "public: void __thiscall winrt::ButtonApp::implementation::MainPageT<struct winrt::ButtonApp::implementation::MainPage>::Connect(int,struct winrt::Windows::Foundation::IInspectable const &)" (?Connect@?$MainPageT@UMainPage@implementation@ButtonApp@winrt@@$$V@implementation@ButtonApp@winrt@@QAEXHABUIInspectable@Foundation@Windows@4@@Z)    ButtonApp   D:\ButtonApp\XamlTypeInfo.g.obj 1   

Thanks for the help folks.感谢帮助的人。

I added a missing "#include <winrt/Windows.UI.Xaml.Input.h>" to the pch.h and it worked.我在 pch.h 中添加了一个缺失的“#include <winrt/Windows.UI.Xaml.Input.h>”并且它起作用了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM