Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29245 Discussions

LINK : error LNK2001: unresolved external symbol _main

miguel_fonseca
Beginner
2,101 Views
Hello,
I am trying to execute small programs samples like, e.g., MenuDialog which can be found in http://www.xeffort.com/fortran/misc/other.htm . But I keep having this link problem: error LNK2001: unresolved external symbol _main

I have followed the common advices, like:
- The project was created within the Win32 Application project type (NOT "Console").
- Having a entry point and to define it in Project Properties>Linker>Advanced>Entry Point. In this case is main:
extern "C" int main() {
HDC hDC = GetDC(NULL);
assert(hDC);
CenterText(hDC, GetSystemMetrics(SM_CXSCREEN) / 2,
GetSystemMetrics(SM_CYSCREEN) / 2, szFace, szMessage, 72);
ReleaseDC(NULL, hDC);
ExitProcess(0);
}
None of them worked, can you give me other advices in this matter?

The software used is:
VS2005 + Intel Fortran Compiler 10.0.026

Thanks for your help,

Regards


0 Kudos
6 Replies
Steven_L_Intel1
Employee
2,101 Views
Where did you read the advice to set a main entry point? Typically a Win32 Application starts execution in a WinMain function (STDCALL, _WinMain@16 on IA-32).
0 Kudos
miguel_fonseca
Beginner
2,101 Views
I saw the entry point advice somewhere in a forum. Yes, I fully agree that a Win32 application starts executing with the function WinMain. When I take out the main entry point it gives me this link error:
LNK2001: unresolved external symbol _WinMainCRTStartup

Which is basically the same error but just with a different name WinMainCRTStartup instead of main.

As I am curious with solving problems I will try to keep searching what is wrong with it.
Meanwhile any suggestions are welcome.
0 Kudos
Les_Neilson
Valued Contributor II
2,101 Views

Miguel,

I have just this minute downloaded the MenuDialog example fromJugoslav's xeffort website. I converted the project from Visual Studio 6 to 2005 then I clicked on the build icon and the code compiled and built without any errors, and I made no other changes to the code.

The resulting executable runs without error, displaying a dialog with two simple menus and buttons.

If you show us what changes you have made to the code then we may be able to helpidentify where you went wrong.

Les

0 Kudos
miguel_fonseca
Beginner
2,101 Views
Les,

I have done the same right now, just to make sure that I did not change anything. Also followed your steps and still got the same LNK2001: unresolved external symbol _WinMainCRTStartup.
I can show you the code from MenuDialog.f90:
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
INTEGER FUNCTION WinMain(hInst, hPInst, lpszCmdLine, nCmdShow)
!DEC$ATTRIBUTES STDCALL, ALIAS: "_WinMain@16" :: WinMain

USE DFLOGM

IMPLICIT NONE

INCLUDE "Resource.fd"

INTEGER, INTENT(IN):: hInst, hPInst, lpszCmdLine, nCmdShow

TYPE(DIALOG):: Dlg
INTEGER:: i
EXTERNAL:: OnDlgInit

i = DlgInit(IDD_DIALOG1, Dlg)
!We need to subclass the window on WM_INITDIALOG
i = DlgSetSub(Dlg, IDD_DIALOG1, OnDlgInit)

i = DlgModal(Dlg)

WinMain = 0

END FUNCTION WinMain
!==============
SUBROUTINE OnDlgInit(Dlg, ID, iEvent)

USE DFLOGM
USE DFWIN, ONLY: SetWindowLong, GWL_WNDPROC

IMPLICIT NONE

TYPE(DIALOG):: Dlg
INTEGER:: ID, iEvent, i

INTERFACE
INTEGER FUNCTION SubclassProc(hWnd, Msg, wParam, lParam)
!DEC$ATTRIBUTES STDCALL:: SubclassProc
INTEGER,INTENT(IN):: hWnd, Msg, wParam, lParam
END FUNCTION
END INTERFACE

!Subclass the dialog after it's initialized
i = SetWindowLong(Dlg%hWnd, GWL_WNDPROC, LOC(SubclassProc))

END SUBROUTINE OnDlgInit
!==============
!Subclassing procedure for the dialog. This has the same type as
!*window* procedure (CallWindowProc), not the dialog procedure
!(return .TRUE./.FALSE.). Note that we don't store "old" window
!proc -- DefDlgProc is the window procedure for all dialogs
!(unless there's non-default dialog class, which is seldom done).
RECURSIVE INTEGER FUNCTION SubclassProc(hWnd, Msg, wParam, lParam)
!DEC$ATTRIBUTES STDCALL:: SubclassProc
USE DFWIN

IMPLICIT NONE

INCLUDE "Resource.fd"

INTEGER,INTENT(IN):: hWnd, Msg, wParam, lParam

INTEGER:: i
LOGICAL, SAVE:: bChecked = .FALSE.

!Calls SendMessage, CallWindowProc and DefDlgProc are semantically identical
!in this case. CallWindowProc is the "cleanest" way to pass the message to
!default procedure, but it triggers an "unresolved external" CVF bug
!(reported, but hard to fix.)

IF (Msg==WM_COMMAND .AND. lParam==0) THEN
!When the command comes from the menu, it has value 0
SELECT CASE(IAND(wParam,#FFFF))
CASE (ID_MENU1_TEST)
!Handle command from the menu.
i = MessageBox(hWnd, "Test"C, "Test"C, MB_OK)
IF (bChecked) THEN
i = CheckMenuItem(GetSubMenu(GetMenu(hWnd),0), ID_MENU1_TEST, MF_BYCOMMAND.OR.MF_UNCHECKED)
ELSE
i = CheckMenuItem(GetSubMenu(GetMenu(hWnd),0), ID_MENU1_TEST, MF_BYCOMM AND.OR.MF_CHECKED)
END IF
bChecked=.NOT.bChecked
SubclassProc = 0
CASE (ID_MENU2_EXIT)
!A little game: fake pressing IDCANCEL :-). ID and code go to
!wParam, handle of the control goes to lParam.
SubclassProc = SendMessage(hWnd, WM_COMMAND, MAKELPARAM(IDCANCEL,BN_CLICKED), GetDlgItem(hWnd,IDCANCEL))
CASE DEFAULT
SubclassProc = CallWindowProc(LOC(DefDlgProc), hWnd, Msg, wParam, lParam)
END SELECT
ELSE
SubclassProc = DefDlgProc(hWnd, Msg, wParam, lParam)
END IF

END FUNCTION SubclassProc
!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

I guess it's exactly the same as yours.
The other files are the resource files, MenuDialog.rc and a .bmp file.

Anyway, I have decided to myself that my deadline to stick with this problem will be tomorrow.
Other urgents things in Visual Fortran have to be made and tested.

Thank you all for your time,
0 Kudos
Les_Neilson
Valued Contributor II
2,101 Views

Miguel,

One important step I forgot to mention : as part of the conversion from VS6 to VS2005.

In the solution explorer window right click on the project and select "Extract Compaq Visual Fortran Project Items" (see the Intel Fortran help section on converting projects)

Then you should be able to compile and build.

Les

0 Kudos
miguel_fonseca
Beginner
2,101 Views
Les,

Thank you very much. The problem is solved. I guess my lack of experience played an important role to make this "problem" last so long.
Now getting ready for the big VF challenges.
Many thanks,
0 Kudos
Reply