unresolved external symbol _MAIN_ referenced in func f90main

Hi,

I’m trying to run some samples from PVF 11.8 and a linker error comes up in some cases, and in others not.
The set project properties, among others, are
Fortran-> Language -> Enable CudaFortran -> yes
Target Accelarators -> Target NVIDIA Accelaratos -> yes

Linker Commnad Line:

-Bstatic -Mcuda -ta=nvidia,wait -o “D:\Projetos\PVFProject5\PVFProject5\Win32\Release\PVFProject5.exe”

For instance in the following case:

[/code]
program BandwidthTest
use TesteBndWidth

call Teste


end program BandwidthTest
Module TesteBndWidth
use cudafor
implicit none

integer, parameter :: nElements = 410241024

! host arrays
real(4) :: a_pageable(nElements), b_pageable(nElements) ! pageable host memory
real(4), allocatable, pinned :: a_pinned(:), b_pinned(:) ! pinned (aka page-locked) host memory, must be allocatable

! device arrays
real(4), device :: a_d(nElements), b_d(nElements)

! events for timing
type (cudaEvent) :: startEvent, stopEvent

! misc
type (cudaDeviceProp) :: prop
real(4) :: time
integer :: istat, i
logical :: pinnedFlag

contains

Subroutine Teste
! allocate and initialize

do i = 1, nElements
a_pageable(i) = i
end do
b_pageable = 0.0

allocate(a_pinned(nElements), b_pinned(nElements), STAT=istat, PINNED=pinnedFlag)
if (istat /= 0) then
write(,) ‘Allocation of a_pinned/b_pinned failed’
pinnedFlag = .false.
else
if (.not. pinnedFlag) write(,) ‘Pinned allocation failed’
end if

if (pinnedFlag) then
a_pinned = a_pageable
b_pinned = 0.0
endif

istat = cudaEventCreate(startEvent)
istat = cudaEventCreate(stopEvent)

! output device info and transfer size
istat = cudaGetDeviceProperties(prop, 0)

write(,)
write(,) 'Device: ', trim(prop%name)
write(,) 'Transfer size (MB): ', 4*nElements/1024./1024.

! pageable data transfers
write(,)
write(,) ‘Pageable transfers’

istat = cudaEventRecord(startEvent, 0)
a_d = a_pageable
istat = cudaEventRecord(stopEvent, 0)
istat = cudaEventSynchronize(stopEvent)

istat = cudaEventElapsedTime(time, startEvent, stopEvent)
write(,) ’ Host to Device bandwidth (GB/s): ', nElements4/time(1.e+3/1024**3)

istat = cudaEventRecord(startEvent, 0)
b_pageable = a_d
istat = cudaEventRecord(stopEvent, 0)
istat = cudaEventSynchronize(stopEvent)

istat = cudaEventElapsedTime(time, startEvent, stopEvent)
write(,) ’ Device to Host bandwidth (GB/s): ', nElements4/time(1.e+3/1024**3)

if (any(a_pageable /= b_pageable)) write(,) ‘*** Pageable transfers failed ***’

! pinned data transfers
if (pinnedFlag) then
write(,)
write(,) ‘Pinned transfers’

istat = cudaEventRecord(startEvent, 0)
a_d = a_pinned
istat = cudaEventRecord(stopEvent, 0)
istat = cudaEventSynchronize(stopEvent)

istat = cudaEventElapsedTime(time, startEvent, stopEvent)
write(,) ’ Host to Device bandwidth (GB/s): ', nElements4/time(1.e+3/1024**3)

istat = cudaEventRecord(startEvent, 0)
b_pinned = a_d
istat = cudaEventRecord(stopEvent, 0)
istat = cudaEventSynchronize(stopEvent)

istat = cudaEventElapsedTime(time, startEvent, stopEvent)
write(,) ’ Device to Host bandwidth (GB/s): ', nElements4/time(1.e+3/1024**3)

if (any(a_pinned /= b_pinned)) write(,) ‘*** Pinned transfers failed ***’
end if

! Device to Device transfer

write(,)
write(,) ‘Transfer between arrays on a (single) device’

istat = cudaEventRecord(startEvent, 0)
b_d = a_d
istat = cudaEventRecord(stopEvent, 0)
istat = cudaEventSynchronize(stopEvent)

istat = cudaEventElapsedTime(time, startEvent, stopEvent)
write(,) ’ Device bandwidth (GB/s): ', 2nElements4/time*(1.e+3/1024**3)
end subroutine Teste

end module

  • Error 1 unresolved external symbol MAIN referenced in function _main f90main.obj
    Error 2 1 unresolved externals D:\Projetos\PVFProject5\PVFProject5\Win32\Release\PVFProject5.exe

Hi ajstuff,

Error 1 unresolved external symbol MAIN referenced in function _main f90main.obj

This means that you don’t have a main program, or at least one is not being included in the link.

While the example code you list does include “program BandwidthTest”, it should get a compile time error since the module “TesteBndWidth” doesn’t exist. Moving the main program below the module definition will allow the source to compile.

Are you seeing other errors besides the unresolved symbol error?

  • Mat

Hi Mat,

thank You very much for Your reply.

As a matter of fact, the main program and the module are already in different files. I tried this, when the same error appeared in the original sample from PVF, where the whole code, with no module, was in the a main unit, in one file.

It seems that some code is beeing added by the compiler ( I could not tell how, maybe from Cuda library) due some wrong set project property causing the trouble with the linker.

I am used to work with Visual Studio from Compaq to Intel environment and Fortram compilers, but It’s my first try with Cuda Fortran

Thanks for any help

ajsuff

Hi ajstuff,

I tried this, when the same error appeared in the original sample from PVF, where the whole code, with no module, was in the a main unit, in one file.

This doesn’t make sense. Can you post your build log? This might give us some hints.

It seems that some code is beeing added by the compiler

Do you mean “MAIN”? Yes, the OS requires all programs have a “main” since this is entry point so the compiler needs to add one.

  • Mat