Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I just want to make a Windows Form in C++. After opening a template, the codeblock appears along with the designer.
Then, I just want to see if the compiler works, so I tried to compile and... it gives me these.

Build started...
1>------ Build started: Project: guessinggame, Configuration: Debug Win32 ------
1>mainWindow.cpp
1>mainWindow.obj : MSIL module encountered; incremental linking is disabled for MSIL; performing full link
1>LINK : error LNK2001: unresolved external symbol _main
1>C:\Users\Karl Steven Renevera\source\repos\guessinggame\Debug\guessinggame.exe : fatal error LNK1120: 1 unresolved externals
1>Done building project "guessinggame.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


I haven't changed ANYTHING YET.
Project Settings are already set to LINKER>System>SubSystem>Windows(/SUBSYSTEM:WINDOWS)
and Entry Point>main

Here's the default code:
C++
#pragma once

namespace guessinggame {

	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 mainWindow
	/// </summary>
	public ref class mainWindow : public System::Windows::Forms::Form
	{
	public:
		mainWindow(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

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

	protected:

	protected:

	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();
			// 
			// mainWindow
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
			this->AutoScaleMode = 
                 System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(1178, 474);
			this->Name = L"mainWindow";
			this->Text = L"mainWindow";
			this->ResumeLayout(false);

		}
#pragma endregion
	};
}


Please help me asap...

What I have tried:

I've already tried the FF:
re-installing VS2019
remaking the project by copy-pasting the code
tried WinForm C++ template
tried C++/clr empty template
Posted
Updated 25-Oct-23 10:47am
v3

IF you get an error you don't understand, Google it: LINK : error LNK2001: unresolved external symbol _main - Google Search[^] There are loads of suggestions there, so have a look and see what fits your exact situation.

We can't see your code - other than the small fragment you show above - or have any idea of your project file and settings, so we can't do much more than you can!
 
Share this answer
 
Set the linker warning level to verbose to see details.

It sounds like you have some misconfiguration in the Configuration Type. Check that you are producing an Application and not some dll.

But the MSIL is a beast so you will spend some time to fix it.
 
Share this answer
 
See Building a Windows Forms Application in C++ environment[^]. Your project should include a source file that includes the main function.
 
Share this answer
 
You need to load the form in main.

My form is named: MainForm.h
My main c++ program is named: mainForm.cpp

In mainForm.cpp add the following code:
------------------------------------------
#include "mainForm.h"

using namespace skemaProgram;

void main() {
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
Application::Run(gcnew mainForm())
}
------------------------------------------

Hope this helps :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900