我知道这是一个常见错误。我已经尝试解决这个问题大约一个星期了。我正在使用 Visual Express 2012 并使用 C++ 进行编码。我启动了一个新的但很空的 win32 应用程序。然后我将一个 UI 表单添加到项目中。在解决方案中有一个头文件和一个我正在使用的 cpp 文件。当我尝试编译时,出现错误 LNK2001 和 LNK1120。
错误1 error LNK2001: unresolved external symbol __tWinMain C:\Users\Me\Desktop\visual c++ workspace\winFormExp01\LINK winFormExp01
错误 2 error LNK1120: 1 unresolved externals C:\Users\Me\Desktop\visual c++ workspace\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) {
}
};
}
.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;
}
我试图让一个基本的 Windows 应用程序以尽可能少的脂肪运行。非常感谢所有帮助。谢谢!