C++ Visual Express 2012 C++;错误LNK2001

C++ Visual Express 2012 C++;错误LNK2001,c++,C++,我知道这是一个常见的错误。我已经试着解决这个问题大约一个星期了。我使用Visual Express 2012和C++编码。我启动了一个新的,但很简单的win32应用程序。然后,我将一个UI表单添加到项目中。在解决方案中,我正在使用一个头文件和一个cpp文件。当我尝试编译时,得到一个错误LNK2001和LNK1120 错误1错误LNK2001:未解析的外部符号 AythTimeCnc:\用户\Me\Tabe\VisualC++工作空间\WiFrimeExp01链接WiFrimExp01 错误2错误

我知道这是一个常见的错误。我已经试着解决这个问题大约一个星期了。我使用Visual Express 2012和C++编码。我启动了一个新的,但很简单的win32应用程序。然后,我将一个UI表单添加到项目中。在解决方案中,我正在使用一个头文件和一个cpp文件。当我尝试编译时,得到一个错误LNK2001和LNK1120

错误1错误LNK2001:未解析的外部符号 AythTimeCnc:\用户\Me\Tabe\VisualC++工作空间\WiFrimeExp01链接WiFrimExp01

错误2错误LNK1120:1未解决 外部C: \用户\Me\Tabe\VisualC++ 工作区\winFormExp01\Debug\winFormExp01.exe winFormExp01

头文件:

#pragma once

namespace winFormExp01 {

    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;

    /// <summary>
    /// Summary for MyForm
    /// </summary>
    public ref class MyForm : public System::Windows::Forms::Form
    {
    public:
        MyForm(void)
        {
            InitializeComponent();
            //
            //TODO: Add the constructor code here
            //
        }

    protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~MyForm()
        {
            if (components)
            {
                delete components;
            }
        }

    private:
        /// <summary>
        /// Required designer variable.
        /// </summary>
        System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        void InitializeComponent(void)
        {
            this->SuspendLayout();
            // 
            // MyForm
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(284, 262);
            this->Name = L"MyForm";
            this->Text = L"MyForm";
            this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
            this->ResumeLayout(false);

        }
#pragma endregion
    private: System::Void MyForm_Load(System::Object^  sender, System::EventArgs^  e) {
             }
    };
}
#pragma一次
名称空间winFormExp01{
使用名称空间系统;
使用名称空间System::ComponentModel;
使用名称空间系统::集合;
使用命名空间System::Windows::Forms;
使用名称空间System::Data;
使用名称空间系统::绘图;
/// 
///我的表格摘要
/// 
公共引用类MyForm:public System::Windows::Forms::Form
{
公众:
我的表格(作废)
{
初始化组件();
//
//TODO:在此处添加构造函数代码
//
}
受保护的:
/// 
///清理所有正在使用的资源。
/// 
~MyForm()
{
if(组件)
{
删除组件;
}
}
私人:
/// 
///必需的设计器变量。
/// 
系统::组件模型::容器^组件;
#pragma区域Windows窗体设计器生成的代码
/// 
///设计器支持所需的方法-不修改
///此方法的内容与代码编辑器一起使用。
/// 
void初始化组件(void)
{
此->SuspendLayout();
// 
//MyForm
// 
这->自动缩放尺寸=系统::图纸::尺寸(6,13);
这->AutoScaleMode=System::Windows::Forms::AutoScaleMode::Font;
这->ClientSize=System::Drawing::Size(284262);
此->名称=L“MyForm”;
此->文本=L“MyForm”;
this->Load+=gcnewsystem::EventHandler(this,&MyForm::MyForm\u Load);
此->恢复布局(错误);
}
#布拉格端区
private:System::Void MyForm_Load(System::Object^sender,System::EventArgs^e){
}
};
}
cpp文件:

#include "MyForm.h"

using namespace System;
using namespace System::Windows::Forms;

[STAThread]
int Main(array<String^>^ args)
{
    Application::EnableVisualStyles();
    Application::SetCompatibleTextRenderingDefault(false);

    winFormExp01::MyForm form;
    Application::Run(%form);
    return 0;
}
#包括“MyForm.h”
使用名称空间系统;
使用命名空间System::Windows::Forms;
[状态线程]
int Main(数组^args)
{
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
winFormExp01::MyForm窗体;
应用程序::运行(%form);
返回0;
}

我正在尝试用尽可能少的fat运行一个基本的windows应用程序。非常感谢您的帮助。谢谢

您必须使用WinMain而不是main

我不确定WinMain应该是什么样子,但是如果您从模板创建一个新的“Windows应用程序”或“Windows窗体”项目,希望其中一个模板中会有它,您可以复制WinMain函数

你可以试试这个吗

void __stdcall WinMain(HINSTANCE hInstance,
             HINSTANCE hPrevInstance,
          long lpCmdLine,
          int nCmdShow)

起始地址是C运行时库中的函数名。链接器根据程序的属性选择它

mainCRTStartup (or wmainCRTStartup) An application using /SUBSYSTEM:CONSOLE; 
calls main (or wmain)

WinMainCRTStartup (or wWinMainCRTStartup) An application using /SUBSYSTEM:WINDOWS; 
calls WinMain (or wWinMain), which must be defined with __stdcall

因此,链接器正在您的程序中查找WinMain,但它找不到并对此进行投诉。

如果您只是在查找Winforms,我会诚实地使用C#。您没有使用CLR+Windows Forms应用程序项目模板。这意味着您可以将大约200种不同的编译器和链接器设置中的任意一种设置错误。我大致知道是哪一个,但你只需要继续下一个你弄错的。使用正确的项目模板毫无意义。我切换到c#,一切似乎都正常。谢谢大家的帮助!