$if def statements

$if def statements

imagem de Brian A.

I have my coding setup to check and see if I am using windows or linux, but what about Mac. THis is what I have for windows and linux tests.

$if def,msnt (for windows)
.....
$endif

$if -def,msnt (for linux)
.....
$endif
15 posts / 0 new
Último post
Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.
imagem de Steve Lionel (Intel)

Well, that won't work on any platform for Intel Fortran. Here's what will:

!DEC$ IF DEFINED(_WIN32)
... ! Windows
!DEC$ ELSE IF DEFINED (__linux__)
... ! Linux
!DEC$ ELSE IF DEFINED (__APPLE__)
... ! Mac OS
!DEC$ ELSE
... Error
!DEC$ END IF

See here for all the predefined symbols.

Steve
imagem de Brian A.
So I added the DEC DEFINE lines, but when I compile on linux, it is pulling in the options for _win32.
If I add to the compiler lie -D_linux_, it pulls in all options for Windows, Linux, and Apple.
*mlist
       subroutine nlssrv
!      This is the subroutine for licensing RELAP
!      Created by: Brian Allison
!
$if def,msnt
       use dflib
$if def,ifortc,1
       use ifport, only: system
$endif
!
       use ufilef
!
       implicit none
$if def,msnt
!dec$ attributes dllimport :: ValidateDLL, CheckLicense
!dec$ attributes dllimport :: InstallLicense, DisplayInstallationID
$endif
!
       logical exis
       integer is, iargc, irc, irc2, irc3, irc4, irc5, irc6, irn, ln2
       integer(4) ValidateDLL, CheckLicense, DisplayInstallationID,
     & InstallLicense
$if -def,msnt 
      integer(4) system
$endif
       character id*12, lcns*22, ln1*18
       character :: syscall1*35 = "nilm -l /usr/lib/libFileMgmt.so -G "
!
!DEC$ IF DEFINED(_WIN32)
!DEC$ ATTRIBUTES ALIAS:'_ValidateDLL' :: ValidateDLL
!DEC$ ATTRIBUTES ALIAS:'_CheckLicense' :: CheckLicense
!DEC$ ATTRIBUTES ALIAS:'_DisplayInstallationID' :: DisplayInstallationID
!DEC$ ATTRIBUTES ALIAS:'_InstallLicense' :: InstallLicense
!DEC$ ATTRIBUTES ALIAS:'_StartTheService' :: StartTheService
!DEC$ ELSE IF DEFINED (__linux__)
!DEC$ ATTRIBUTES ALIAS:'ValidateDLL' :: ValidateDLL
!DEC$ ATTRIBUTES ALIAS:'CheckLicense' :: CheckLicense
!DEC$ ATTRIBUTES ALIAS:'DisplayInstallationID' :: DisplayInstallationID
!DEC$ ATTRIBUTES ALIAS:'InstallLicense' :: InstallLicense
!DEC$ ELSE IF DEFINED (__APPLE__)
!DEC$ ATTRIBUTES ALIAS:'_ValidateDLL' :: ValidateDLL
!DEC$ ATTRIBUTES ALIAS:'_CheckLicense' :: CheckLicense
!DEC$ ATTRIBUTES ALIAS:'_DisplayInstallationID' :: DisplayInstallationID
!DEC$ ATTRIBUTES ALIAS:'_InstallLicense' :: InstallLicense
!DEC$ END IF
!
!  Check license.
!DEC$ IF DEFINED(_WIN32)
         call StartTheService
!DEC$ END IF
!      Random Number
         irn = 12
         irc3 = ValidateDLL (3009, 9445, irn)
         irc = CheckLicense (irn)
         irc2 = DisplayInstallationID (id)
         write (tty,"('License Status:',i10)") irc
         write (tty,"('Installation ID:',a13)") id
!DEC$ IF DEFINED(_linux_)
         irc5 = system("nilm -l /usr/lib/libFileMgmt.so -I")
!DEC$ END IF
!DEC$ IF DEFINED(_linux_)
         if (irc .eq. -4) then
           is = 0
           do
             write (tty,"('E-mail the Installation ID, found on this scr
     &een to issnet@cableone.net.'/'Please key in the 15 digit unlock co
     &de that you recieved in your e-mail'/'after sending in the Install
     &ation ID.'/)")
             read (5,"(a)") ln1 !15 character unlock code
             ln2 = len_trim(ln1) !Measure the length of the unlcok code
             if (ln2 .ne. 15) then
               write (tty,"('15 character unlock code was not entered
     &.')")
             else 
               irc6 = system(syscall1//ln1)
               if (irc .lt. 0) then
                 write (tty,"('License Status:', i10)") irc
                 stop "Unlock code was incorrect"
               exit
             endif
             is = is + 1
             if (is .lt. 3) cycle
             stop 'Unlock code was not entered properly.'
           enddo
           stop
         endif
!DEC$ END IF
!DEC$ IF DEFINED(_WIN32)
         inquire (file="licensedata.txt",exist=exis)
         if (exis) then
           open (unit=output,file="licensedata.txt",status='old',
     &     form='formatted')
           close (output, dispose='delete')
         endif
!DEC$ END IF
         lcns = " "
         irc4 = InstallLicense (lcns)
!DEC$ IF DEFINED(_WIN32)
         if (irc .lt. 0) then
           write (tty,"('Problewm with license!  Please contact Innovati
     &ve Systems software with error code and installation id.'/'issnet@
     &cableone.net')")
           stop 
         endif
!DEC$ END IF
         if (irc .eq. 10000) then
           write (tty,"(' LicenseStatus: License is active')")
         endif
         if (irc .eq. -108) then
           write (tty,"(' RELAP5 folder must have full administrative ri
     &ghts')")
         endif
         if (irc.lt.365 .and. irc.gt.0) then
           write (tty,"(' LicenseStatus:',i10,' Days left')") irc
         endif
!
       end subroutine nlssrv
imagem de Steve Lionel (Intel)

You should not add -D for the platform names - these are predefined by the compiler. Did you leave in those $if lines?

Steve
imagem de Brian A.

Are you referring to these:

  1. $ifdef,msnt(forwindows)
  2. .....
  3. $endif
  4. $if-def,msnt(forlinux)
  5. .....
  6. $endif
I took them out. Also, linux and apple are not defined. THe manual says that you have to define them at the start of compilation.
imagem de Steve Lionel (Intel)

You should not define the linux and apple symbols (nor WIN32). The compiler supplies the appropriate definition depending on the platform you compile on.

Steve
imagem de Brian A.

ok so then why when I compile on linux does it load the win32 items?

imagem de Steve Lionel (Intel)

I can't say without seeing the actual code you're trying and the commands you're using. Try building the attached program on the different platforms with just "ifort platform.f90" and run it. What do you get?

Anexos: 

AnexoTamanho
Download platform.f90219 bytes
Steve
imagem de Brian A.

I typed "ifort platform.f90" on my mac and got new prompt

imagem de mecej4

Run the resulting program and see what it prints.

imagem de Brian A.

what resulting program? It did not create any new files. all there is is platform.f90. oh wait there is a file called a.out.

imagem de Brian A.

OK I figured it out. It says MAC OS! SO why when I run a linux compile program it is using the options under the _win32 decloration? Is it because I am compiling on a virtual Linux machine on my Win 7 computer?

imagem de Brian A.

I just tried platform.f90 on my virtual linux on my mac and it says LINUX

imagem de mecej4

If it gave anything else, we could conclude that the VM implementation was defective or that you had lost awareness of whether you were running inside the host or the guest OS -- the latter is not plausible since the look-and-feel is quite different between the host and the guest.

imagem de Steve Lionel (Intel)

The compiler is what determines the value and it is specific to the target platform of the compiler. It doesn't "detect" the OS.

Steve

Faça login para deixar um comentário.