<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Approximatrix Forums — making dll to use in R]]></title>
	<link rel="self" href="https://forums.approximatrix.com/extern.php?action=feed&amp;tid=494&amp;type=atom" />
	<updated>2015-10-03T04:28:36Z</updated>
	<generator>PunBB</generator>
	<id>https://forums.approximatrix.com/viewtopic.php?id=494</id>
		<entry>
			<title type="html"><![CDATA[Re: making dll to use in R]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=2226#p2226" />
			<content type="html"><![CDATA[<p>Hi David,<br />The problem is solved and everything is working now. I have been using the following R commands to call DLLs into R that are created using free compilers (32-bit MinGW, gfortran, gcc):&nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; dyn.load(&quot;C:/Users/Sam27/Desktop/projects/add.dll&quot;)<br />&nbsp; &nbsp; &nbsp; &nbsp; .C(&quot;add_&quot;, as.integer(-999), as.integer(10), as.integer(15)) : </p><p>However, I needed to modify the R code slightly to call the DLLs created using SimplyFortran; here is the corrected code: <br />&nbsp; &nbsp; &nbsp; &nbsp; dyn.load(&quot;C:/Users/Sam27/Desktop/projects/add.dll&quot;)<br />&nbsp; &nbsp; &nbsp; &nbsp; .C(&quot;add&quot;, as.integer(-999), as.integer(10), as.integer(15)) : </p><p>Your suggestions helped me try it differently. Thank you very much.&nbsp; </p><p>Best regards,<br />Sam</p>]]></content>
			<author>
				<name><![CDATA[ms.warasi]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=3638</uri>
			</author>
			<updated>2015-10-03T04:28:36Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=2226#p2226</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: making dll to use in R]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=2225#p2225" />
			<content type="html"><![CDATA[<p>It looks like its just a name mangling error where the name in the DLL doesn&#039;t match what you have in the Fortran code.</p><p>I am not familiar with R&#039;s requirements.</p><p>Try changing your code to the following to ensure the dll contains a subroutine actually called &quot;add&quot;. You need to be compiling for Fortran 2003 for BIND to be accepted.</p><div class="codebox"><pre><code>      subroutine add(sm,a,b) bind(C, name=&quot;add&quot;)
      implicit none
      integer sm, a, b
      sm = a + b
      return
      end</code></pre></div><p>Also should your load command be:</p><p>dyn.load(&quot;C:\Users\Sam27\Desktop\projects\add.dll&quot;)</p><p>or even</p><p>dyn.load(&quot;C:\\Users\\Sam27\\Desktop\\projects\\add.dll&quot;)</p><p>?</p>]]></content>
			<author>
				<name><![CDATA[davidb]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=3463</uri>
			</author>
			<updated>2015-10-01T21:41:42Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=2225#p2225</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: making dll to use in R]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=2224#p2224" />
			<content type="html"><![CDATA[<p>Hi Jeff,<br />Thanks for your reply; and I am sorry for my delayed response. Unfortunately, my problem has not been solved yet. </p><p>I forgot to mention that I am changing the architecture correctly from the (default) 32-bit to 64-bit, when I am using a 64-bit R. </p><p>I think your second comment addresses my problem. I think the DLL is not created properly. When I open the 64-bit DLL, that is, add.dll, from file menu (File &gt; Open &gt; add.dll), I don&#039;t find &#039;add_&#039; among the bunch of symbols, such as, 6c3ca3a8 b .bss. </p><p>Am I making any mistake? Do you have any thoughts on this? Or, is it because I am using a trial version of SimplyFortran? </p><p>Best regards,<br />Sam</p>]]></content>
			<author>
				<name><![CDATA[ms.warasi]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=3638</uri>
			</author>
			<updated>2015-10-01T19:38:51Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=2224#p2224</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: making dll to use in R]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=2217#p2217" />
			<content type="html"><![CDATA[<p>Sam,</p><p>One thing&nbsp; I noticed from your description is that you didn&#039;t mention changing the architecture to 64-bit.&nbsp; If you&#039;re attempting to access the DLL from 64-bit R, the DLL will need to be 64-bit as well.</p><p>You can also see what names are exported in the DLL you&#039;ve compiled by opening it (just by selecting Open in the File menu) in Simply Fortran.&nbsp; You should be presented with a list of symbols, and you can search for &quot;add_&quot; to make sure it&#039;s available and named properly.</p>]]></content>
			<author>
				<name><![CDATA[jeff]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=2</uri>
			</author>
			<updated>2015-09-23T15:13:08Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=2217#p2217</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[making dll to use in R]]></title>
			<link rel="alternate" href="https://forums.approximatrix.com/viewtopic.php?pid=2216#p2216" />
			<content type="html"><![CDATA[<p>Hello,<br />I need to call Fortran subroutines into a 64-bit R through dll files. My main goal is to share my research-codes through dll files, so that practitioners can use them. To create a 64-bit dll, I am currently using the SimplyFortran trial version. I have created the dll in SimplyFortran, but the dll doesn’t work in R. I am very new to SimplyFortran and not sure if I am making any mistakes. Here is a (f77) sample code that I am trying to use in R: </p><p>&nbsp; &nbsp; &nbsp; subroutine add(sm,a,b)<br />&nbsp; &nbsp; &nbsp; implicit none<br />&nbsp; &nbsp; &nbsp; integer sm, a, b<br />&nbsp; &nbsp; &nbsp; sm = a + b<br />&nbsp; &nbsp; &nbsp; return<br />&nbsp; &nbsp; &nbsp; end</p><p>To create the dll in SimplyFortran, I save and open the ‘An empty static library project’ and follow the steps: <br />(1)&nbsp; &nbsp; Click on Project &gt; Add files(s)… &gt; choose the subroutine add.f90 <br />(2)&nbsp; &nbsp; Project &gt; Options… &gt; Target Name: add.dll<br />(3)&nbsp; &nbsp; Build &gt; Build now! </p><p>Here is how I load the dll in R: <br />dyn.load(&quot;C:/Users/Sam27/Desktop/projects/add.dll&quot;)</p><p>Here is the error msg: <br />Error in .C(&quot;add_&quot;, as.integer(-999), as.integer(10), as.integer(15)) : <br />&nbsp; C symbol name &quot;add_&quot; not in load table</p><p>I see that similar problems have been discussed, but I have not been able to solve mine. Would you please give me helpful comments? I will really appreciate it. </p><p>Best regards,<br />Sam</p>]]></content>
			<author>
				<name><![CDATA[ms.warasi]]></name>
				<uri>https://forums.approximatrix.com/profile.php?id=3638</uri>
			</author>
			<updated>2015-09-22T08:01:23Z</updated>
			<id>https://forums.approximatrix.com/viewtopic.php?pid=2216#p2216</id>
		</entry>
</feed>
