title: Build shared object from Fortran source with package(e.g. LAPACK) for R
body: <p>I am new to create shared objects for R from Fortran sources. Perhaps some of my questions do not make sense. However, I have searched a lot about my questions but still get no clear answer. So, I would like to figure out what the big picture to create these shared objects(.dll files)in R is.</p>
  
  <p>According some tutorials and manuals, I need to prepare a Fortran file <em>mymodf.f</em>, which contains only subroutines, similarly as below:</p>
  
  <pre><code>c file mymodf.f
     subroutine initmod(odeparms)
      external odeparms
      double precision parms(3)
      common /myparms/parms
  
       call odeparms(3, parms)
      return
     end
  
     subroutine derivs (neq, t, y, ydot, yout, ip)
      ....
      return
     end
  
     subroutine jac (neq, t, y, ml, mu, pd, nrowpd, yout, ip)
      ....
      return
     end
  c end of file mymodf.f
  </code></pre>
  
  <p>In order to create the shared object, it requires the following code:</p>
  
  <pre><code>system("R CMD SHLIB mymodf.f")
  </code></pre>
  
  <p>I want to use the subroutines in LAPACK to solve some linear equations or inverse matrices. What should I do so that I can call the subroutines in LAPACK? I ask this question because one needs to install packages in R to call some extra functions or one needs to add <code>#include &lt;xxxx.h&gt;</code> as header in C to call some extra functions in xxxx.h. Just the same situation.</p>
  
  <p>Also, I have downloaded lapack-3.5.0.tgz from <a href="http://www.netlib.org/lapack" rel="nofollow">http://www.netlib.org/lapack</a>. Where should I put package to? Do I need to install this .tgz file?</p>
  
  <p>This is not a normal case to code, compile and run a Fortran program. I have some Fortran codes which is not a complete program and I want to complie it as .dll file for R.</p>
  
  <p>Thanks very much for helping!</p>
  
  <p>(FYI, I am working on a Windows 7 PC)</p>