LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   compilation problem (https://www.linuxquestions.org/questions/linux-newbie-8/compilation-problem-940297/)

Nagat 04-17-2012 01:29 PM

compilation problem
 
Hi Linux users

I'm new in Linux. I tried to compile a Fortran program in ubuntu 11.10
with gcc. My fortran program is monte_pi. I saved it in the Desktop. But when I changed directory to /home/nagat/Desktop and run
gcc -o monte_pi monte_pi.f . An error appeared to me
gcc:error:monte_pi: no such file or directory
gcc:fatal error:no input file
compilation terminated
please can any one help me to get over this error?
Thanks in advance

Bests
Nagat

LegalBreaker 04-17-2012 01:34 PM

Make sure you are in the correct directory with 'pwd'. Make sure that the file exists with 'ls'. It looks like the compiler cannot find monte_pi.f.

knudfl 04-17-2012 02:01 PM

Welcome to LQ. http://www.dartmouth.edu/~rc/classes...simple_ex.html
The file name is monte_pi.f : It's a Fortran program → gcc cannot be used.

Ubuntu 11.10 : 1) sudo apt-get install gfortran
2) gfortran -c monte_pi.f
3) gfortran -o monte_pi monte_pi.o : You get the executable 'monte_pi'.
... Or the simple way (2)(3) : gfortran monte_pi.f -o monte_pi
4) Run the pi test : ./monte_pi
Code:

C Program to compute Pi using monte carlo methods

      program monte_pi
      implicit none
     
      integer niter,i,j
      integer seed
      real*4 count
      real *8 x,y,pi(100),z
      real*8  rand
     
C initialize random numbers
      seed = 35791246
      call srand (seed)
      do j= 1,100
          niter = niter+100
          count =0
          do i=1,niter
            x=rand()
            y=rand()
            z= x*x +y*y
            if (z .le. 1) count =count+1
          end do
          pi(j)= count/niter*4.
          write(*,10) niter,pi(j)
10        format('Number of trials is: 'i5,'  estimate of pi is:',f8.5)
      end do
      end



.


All times are GMT -5. The time now is 01:43 AM.