<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Approximatrix Forums — how to include a .dll file in the project?]]></title>
		<link>https://forums.approximatrix.com/viewtopic.php?id=485</link>
		<atom:link href="https://forums.approximatrix.com/extern.php?action=feed&amp;tid=485&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in how to include a .dll file in the project?.]]></description>
		<lastBuildDate>Sat, 22 Aug 2015 01:35:30 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: how to include a .dll file in the project?]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=2171#p2171</link>
			<description><![CDATA[<p>Hi Jeff,</p><p>&nbsp; &nbsp; It seems that NLopt is really working now in my project! <img src="https://forums.approximatrix.com/img/smilies/smile.png" width="15" height="15" alt="smile" /> Thanks again! </p><p>&nbsp; &nbsp; Now I have another question about profiler. I think it&#039;s probably a better idea starting a new thread for future search:)</p>]]></description>
			<author><![CDATA[null@example.com (wwang328)]]></author>
			<pubDate>Sat, 22 Aug 2015 01:35:30 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=2171#p2171</guid>
		</item>
		<item>
			<title><![CDATA[Re: how to include a .dll file in the project?]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=2170#p2170</link>
			<description><![CDATA[<p>That&#039;s great to hear!&nbsp; If you encounter any other problems or have some further suggestions, please do post here.</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Thu, 20 Aug 2015 13:33:37 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=2170#p2170</guid>
		</item>
		<item>
			<title><![CDATA[Re: how to include a .dll file in the project?]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=2169#p2169</link>
			<description><![CDATA[<p>Hi Jeff, Thank you so much for your fast response!:) After stucking there for a day or two, the program is finally running and giving results! <img src="https://forums.approximatrix.com/img/smilies/smile.png" width="15" height="15" alt="smile" />&nbsp; Now I can continue to work out the real problem now!~</p>]]></description>
			<author><![CDATA[null@example.com (wwang328)]]></author>
			<pubDate>Thu, 20 Aug 2015 00:54:56 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=2169#p2169</guid>
		</item>
		<item>
			<title><![CDATA[Re: how to include a .dll file in the project?]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=2168#p2168</link>
			<description><![CDATA[<p>In this case, the linker is failing because you&#039;ve compiled your Fortran code for a 32-bit target, but you&#039;re trying to use it with a 64-bit DLL.&nbsp; If you open Project Options and switch to 64-bit architecture (remember to save your project afterwards!), you should be able to compile and link properly.</p><p>The missing functions you&#039;re seeing are only because you&#039;re using a 64-bit DLL with code you compiled as 32-bit.&nbsp; Once you fix that error, you might run into another issue with the trailing underscore, but perhaps not.&nbsp; The link you&#039;ve provided is for Intel&#039;s Fortran compiler, and I don&#039;t know how it treats C vs. Fortran function decorations.&nbsp; It&#039;s best to ignore the link you&#039;ve provided for now.</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Thu, 20 Aug 2015 00:48:22 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=2168#p2168</guid>
		</item>
		<item>
			<title><![CDATA[Re: how to include a .dll file in the project?]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=2167#p2167</link>
			<description><![CDATA[<p>OK. Stackoverflow helps me to identify the misplaced $ sign in calling nlo_add_inequality_constraint and it should be in the 6th indention before the rest of codes.</p><p>&nbsp; &nbsp; &nbsp;Fixing that, the test.f file can be built. But I got the following error message </p><p>&nbsp; &nbsp; </p><div class="codebox"><pre><code> c:/program files (x86)/simply fortran/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/lib/../lib32\libmingw32.a(lib32_libmingw32_a-CRT_fp10.o):CRT_fp10.c:(.text+0x0): multiple definition of `fpreset&#039;
.\libnlopt-0.dll:/build/mingw-w64-RGpMuZ/mingw-w64-2.0.3/build/x86_64-w64-mingw32/all/mingw-w64-crt/../../../../mingw-w64-crt/crt/CRT_fp10.c:12: first defined here
c:/program files (x86)/simply fortran/mingw-w64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/bin/ld.exe: i386:x86-64 architecture of input file `.\libnlopt-0.dll&#039; is incompatible with i386 output
build\test.o: In function `MAIN__&#039;:
D:\Dropbox\fortran\nlopt-2.4.2-dll64/./test.f:11: undefined reference to `nlo_create_&#039;
D:\Dropbox\fortran\nlopt-2.4.2-dll64/./test.f:12: undefined reference to `nlo_get_lower_bounds_&#039;
D:\Dropbox\fortran\nlopt-2.4.2-dll64/./test.f:14: undefined reference to `nlo_set_lower_bounds_&#039;
D:\Dropbox\fortran\nlopt-2.4.2-dll64/./test.f:15: undefined reference to `nlo_set_min_objective_&#039;
D:\Dropbox\fortran\nlopt-2.4.2-dll64/./test.f:20: undefined reference to `nlo_add_inequality_constraint_&#039;
D:\Dropbox\fortran\nlopt-2.4.2-dll64/./test.f:24: undefined reference to `nlo_add_inequality_constraint_&#039;
D:\Dropbox\fortran\nlopt-2.4.2-dll64/./test.f:26: undefined reference to `nlo_set_xtol_rel_&#039;
D:\Dropbox\fortran\nlopt-2.4.2-dll64/./test.f:30: undefined reference to `nlo_optimize_&#039;
D:\Dropbox\fortran\nlopt-2.4.2-dll64/./test.f:38: undefined reference to `nlo_destroy_&#039;
collect2.exe: error: ld returned 1 exit status
Error(E42): Last command making (Project.exe) returned a bad status
Error(E02): Make execution terminated </code></pre></div><p>&nbsp; &nbsp; &nbsp;According to one post <a href="http://permalink.gmane.org/gmane.science.analysis.nlopt.general/662">http://permalink.gmane.org/gmane.scienc … eneral/662</a> here, it seems any Fortran function fun should have a C name fun_. <img src="https://forums.approximatrix.com/img/smilies/roll.png" width="15" height="15" alt="roll" /> </p><p>&nbsp; &nbsp; &nbsp;The post is not illustrative though, at least not to beginners like me.... Would you suggest how to fix that? Thanks again!</p>]]></description>
			<author><![CDATA[null@example.com (wwang328)]]></author>
			<pubDate>Wed, 19 Aug 2015 22:43:19 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=2167#p2167</guid>
		</item>
		<item>
			<title><![CDATA[Re: how to include a .dll file in the project?]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=2166#p2166</link>
			<description><![CDATA[<p>That makes sense. Thanks, Jeff! </p><p>&nbsp; &nbsp; &nbsp; &nbsp;I later found out the example in NLopt website is written in fortram 77 <a href="http://ab-initio.mit.edu/wiki/index.php/NLopt_Tutorial.">http://ab-initio.mit.edu/wiki/index.php/NLopt_Tutorial.</a> <br />But changing the extension of test.f90 into test.f does not work. </p><p>&nbsp; &nbsp; &nbsp; &nbsp;The following question might be a bit off of the original theme and may sound stupid, since it&#039;s likely to be caused by my infamilarity with Fortran 77 language. </p><p>&nbsp; &nbsp; &nbsp; &nbsp; So here is the test. f file, with 6 indents for every line: <br />&nbsp; &nbsp; </p><div class="codebox"><pre><code>      program main
      external myfunc, myconstraint
      double precision lb(2)
      integer*8 opt
      double precision d1(2), d2(2)
      double precision x(2), minf
      integer ires
      include &#039;nlopt.f&#039;
      
      opt=0
      call nlo_create(opt, NLOPT_LD_MMA, 2)
      call nlo_get_lower_bounds(ires, opt, lb)
      lb(2) = 0.0
      call nlo_set_lower_bounds(ires, opt, lb)
      call nlo_set_min_objective(ires, opt, myfunc, 0)
     
      d1(1) = 2.
      d1(2) = 0.
      call nlo_add_inequality_constraint(ires, opt, myconstraint, 
      $ d1, 1.D-8)
      d2(1) = -1.
      d2(2) = 1.
      call nlo_add_inequality_constraint(ires, opt, myconstraint, 
      $ d2, 1.D-8)
     
      call nlo_set_xtol_rel(ires, opt, 1.D-4)
     
      x(1) = 1.234
      x(2) = 5.678
      call nlo_optimize(ires, opt, x, minf)
      if (ires.lt.0) then
        write(*,*) &#039;nlopt failed!&#039;
      else
        write(*,*) &#039;found min at &#039;, x(1), x(2)
        write(*,*) &#039;min val = &#039;, minf
      endif
     
      call nlo_destroy(opt)
     
      end 
     
      subroutine myfunc(val, n, x, grad, need_gradient, f_data)
      double precision val, x(n), grad(n)
      integer n, need_gradient
      if (need_gradient.ne.0) then
         grad(1) = 0.0
         grad(2) = 0.5 / dsqrt(x(2))
      endif
      val = dsqrt(x(2))
      end 
     
      subroutine myconstraint(val, n, x, grad, need_gradient, d)
      integer need_gradient
      double precision val, x(n), grad(n), d(2), a, b
      a = d(1)
      b = d(2)
      if (need_gradient.ne.0) then
        grad(1) = 3. * a * (a*x(1) + b)**2
        grad(2) = -1.0
      endif
      val = (a*x(1) + b)**3 - x(2)
      end               </code></pre></div><p> </p><p>&nbsp; &nbsp; &nbsp; I compile it with libnlopt-0.def, libnlopt-0.dll, nlopt.f (disabled) and test.f under the project and receives such info: </p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;C:\Program Files (x86)\Simply Fortran\mingw-w64\bin\gfortran.exe&quot; -c -o &quot;build\test.o&quot; -g -m32&nbsp; &nbsp;-Jmodules &quot;.\test.f&quot;<br />.\test.f:19.72:</p><p>&nbsp; &nbsp; &nbsp; call nlo_add_inequality_constraint(ires, opt, myconstraint, d1, 1.<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1<br />Error: Syntax error in argument list at (1)<br />.\test.f:22.72:</p><p>&nbsp; &nbsp; &nbsp; call nlo_add_inequality_constraint(ires, opt, myconstraint, d2, 1.<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 1<br />Error: Syntax error in argument list at (1)<br />Error(E42): Last command making (build\test.o) returned a bad status<br />Error(E02): Make execution terminated</p><p>&nbsp; &nbsp; &nbsp; &nbsp;This seems weird as (i) it&#039;s a copied code from website (ii) it matches the format requirement in the reference <br />&nbsp; </p><div class="codebox"><pre><code> call nlo_add_inequality_constraint(ires, opt, fc, fc_data, tol) </code></pre></div><p>I doubt there&#039;s some stupid error there, and I would sincerely appreciate if you can have a look at that!</p>]]></description>
			<author><![CDATA[null@example.com (wwang328)]]></author>
			<pubDate>Wed, 19 Aug 2015 19:31:01 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=2166#p2166</guid>
		</item>
		<item>
			<title><![CDATA[Re: how to include a .dll file in the project?]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=2165#p2165</link>
			<description><![CDATA[<p>The file <em>nlopt.f</em> shouldn&#039;t be compiled separately.&nbsp; As you may have noticed, it contains only parameter definitions.&nbsp; When the compiler encounters this file, it gets confused since it doesn&#039;t actually do anything other than declare variables.</p><p>Assuming your test program <em>test.f90</em> is already <strong>INCLUDE</strong>-ing the file <em>nlopt.f</em>, you need to tell Simply Fortran that it shouldn&#039;t be compiled separately.&nbsp; In the Project Outline panel, right-click on <em>nlopt.f</em> and select &quot;Disable File&quot; from the popup menu.&nbsp; Simply Fortran will now no longer attempt to compile <em>nlopt.f</em> on its own.</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Wed, 19 Aug 2015 15:46:39 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=2165#p2165</guid>
		</item>
		<item>
			<title><![CDATA[Re: how to include a .dll file in the project?]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=2164#p2164</link>
			<description><![CDATA[<p>Thank you for your reply, Jeff! I&#039;ve followed what you suggests and carried out a test program, which is an example Fortram code copied from NLOPT website (let me name it test.f90). That means, the way using DLL file should be fine.</p><p>&nbsp; &nbsp; With all files under the project in the same directory (test.f90, nlopt.f, libnlopt-0.dll, libnlopt-0.def), here is the error message that comes to me after I build it: </p><p>&nbsp; &nbsp; Error: Unexpected end of file in &#039;.\nlopt.f&#039;<br />&nbsp; &nbsp; Error(E42): Last command making (build\nlopt.o) returned a bad status<br />&nbsp; &nbsp; Error(E02): Make execution terminated</p><p>Is it because nlopt.f is written in Fortran 77? Shouldn&#039;t .f file still able to be compiled by SF? Here&#039;s how nlopt.f is written: </p><p>&nbsp; &nbsp;</p><div class="codebox"><pre><code>       integer NLOPT_GN_DIRECT
      parameter (NLOPT_GN_DIRECT=0)
      integer NLOPT_GN_DIRECT_L
      parameter (NLOPT_GN_DIRECT_L=1)
      integer NLOPT_GN_DIRECT_L_RAND
      parameter (NLOPT_GN_DIRECT_L_RAND=2)
      integer NLOPT_GN_DIRECT_NOSCAL
      parameter (NLOPT_GN_DIRECT_NOSCAL=3)
      integer NLOPT_GN_DIRECT_L_NOSCAL
      parameter (NLOPT_GN_DIRECT_L_NOSCAL=4)
      integer NLOPT_GN_DIRECT_L_RAND_NOSCAL
      parameter (NLOPT_GN_DIRECT_L_RAND_NOSCAL=5)
      integer NLOPT_GN_ORIG_DIRECT
      parameter (NLOPT_GN_ORIG_DIRECT=6)
      integer NLOPT_GN_ORIG_DIRECT_L
      parameter (NLOPT_GN_ORIG_DIRECT_L=7)
      integer NLOPT_GD_STOGO
      parameter (NLOPT_GD_STOGO=8)
      integer NLOPT_GD_STOGO_RAND
      parameter (NLOPT_GD_STOGO_RAND=9)
      integer NLOPT_LD_LBFGS_NOCEDAL
      parameter (NLOPT_LD_LBFGS_NOCEDAL=10)
      integer NLOPT_LD_LBFGS
      parameter (NLOPT_LD_LBFGS=11)
      integer NLOPT_LN_PRAXIS
      parameter (NLOPT_LN_PRAXIS=12)
      integer NLOPT_LD_VAR1
      parameter (NLOPT_LD_VAR1=13)
      integer NLOPT_LD_VAR2
      parameter (NLOPT_LD_VAR2=14)
      integer NLOPT_LD_TNEWTON
      parameter (NLOPT_LD_TNEWTON=15)
      integer NLOPT_LD_TNEWTON_RESTART
      parameter (NLOPT_LD_TNEWTON_RESTART=16)
      integer NLOPT_LD_TNEWTON_PRECOND
      parameter (NLOPT_LD_TNEWTON_PRECOND=17)
      integer NLOPT_LD_TNEWTON_PRECOND_RESTART
      parameter (NLOPT_LD_TNEWTON_PRECOND_RESTART=18)
      integer NLOPT_GN_CRS2_LM
      parameter (NLOPT_GN_CRS2_LM=19)
      integer NLOPT_GN_MLSL
      parameter (NLOPT_GN_MLSL=20)
      integer NLOPT_GD_MLSL
      parameter (NLOPT_GD_MLSL=21)
      integer NLOPT_GN_MLSL_LDS
      parameter (NLOPT_GN_MLSL_LDS=22)
      integer NLOPT_GD_MLSL_LDS
      parameter (NLOPT_GD_MLSL_LDS=23)
      integer NLOPT_LD_MMA
      parameter (NLOPT_LD_MMA=24)
      integer NLOPT_LN_COBYLA
      parameter (NLOPT_LN_COBYLA=25)
      integer NLOPT_LN_NEWUOA
      parameter (NLOPT_LN_NEWUOA=26)
      integer NLOPT_LN_NEWUOA_BOUND
      parameter (NLOPT_LN_NEWUOA_BOUND=27)
      integer NLOPT_LN_NELDERMEAD
      parameter (NLOPT_LN_NELDERMEAD=28)
      integer NLOPT_LN_SBPLX
      parameter (NLOPT_LN_SBPLX=29)
      integer NLOPT_LN_AUGLAG
      parameter (NLOPT_LN_AUGLAG=30)
      integer NLOPT_LD_AUGLAG
      parameter (NLOPT_LD_AUGLAG=31)
      integer NLOPT_LN_AUGLAG_EQ
      parameter (NLOPT_LN_AUGLAG_EQ=32)
      integer NLOPT_LD_AUGLAG_EQ
      parameter (NLOPT_LD_AUGLAG_EQ=33)
      integer NLOPT_LN_BOBYQA
      parameter (NLOPT_LN_BOBYQA=34)
      integer NLOPT_GN_ISRES
      parameter (NLOPT_GN_ISRES=35)
      integer NLOPT_AUGLAG
      parameter (NLOPT_AUGLAG=36)
      integer NLOPT_AUGLAG_EQ
      parameter (NLOPT_AUGLAG_EQ=37)
      integer NLOPT_G_MLSL
      parameter (NLOPT_G_MLSL=38)
      integer NLOPT_G_MLSL_LDS
      parameter (NLOPT_G_MLSL_LDS=39)
      integer NLOPT_LD_SLSQP
      parameter (NLOPT_LD_SLSQP=40)
      integer NLOPT_LD_CCSAQ
      parameter (NLOPT_LD_CCSAQ=41)
      integer NLOPT_GN_ESCH
      parameter (NLOPT_GN_ESCH=42)
      integer NLOPT_FAILURE
      parameter (NLOPT_FAILURE=-1)
      integer NLOPT_INVALID_ARGS
      parameter (NLOPT_INVALID_ARGS=-2)
      integer NLOPT_OUT_OF_MEMORY
      parameter (NLOPT_OUT_OF_MEMORY=-3)
      integer NLOPT_ROUNDOFF_LIMITED
      parameter (NLOPT_ROUNDOFF_LIMITED=-4)
      integer NLOPT_FORCED_STOP
      parameter (NLOPT_FORCED_STOP=-5)
      integer NLOPT_SUCCESS
      parameter (NLOPT_SUCCESS=1)
      integer NLOPT_STOPVAL_REACHED
      parameter (NLOPT_STOPVAL_REACHED=2)
      integer NLOPT_FTOL_REACHED
      parameter (NLOPT_FTOL_REACHED=3)
      integer NLOPT_XTOL_REACHED
      parameter (NLOPT_XTOL_REACHED=4)
      integer NLOPT_MAXEVAL_REACHED
      parameter (NLOPT_MAXEVAL_REACHED=5)
      integer NLOPT_MAXTIME_REACHED
      parameter (NLOPT_MAXTIME_REACHED=6)</code></pre></div><p> </p><p> Sorry for the long post and I hope I made my question clear. Thanks!</p>]]></description>
			<author><![CDATA[null@example.com (wwang328)]]></author>
			<pubDate>Tue, 18 Aug 2015 17:34:11 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=2164#p2164</guid>
		</item>
		<item>
			<title><![CDATA[Re: how to include a .dll file in the project?]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=2163#p2163</link>
			<description><![CDATA[<p>I believe you&#039;ve downloaded the pre-compiled binaries for Windows if I&#039;m not mistaken.&nbsp; These files should work fine.&nbsp; The file <em>nlopt.f</em> is actually just a list of parameters that you&#039;d probably include in any routines needing it via:</p><div class="codebox"><pre><code>INCLUDE &#039;nlopt.f&#039;</code></pre></div><p>You&#039;ll need to make sure the file is in the same directory as the rest of your source code.&nbsp; You&#039;ll also need to compile and link against the DLL.&nbsp; The simplest way to do this might be to actually add the DLL to your project.&nbsp; From the Project menu, select &quot;Add File(s)...&quot; and select &quot;libnlopt-0.dll.&quot;&nbsp; When you build your program now, it should link against the DLL properly.&nbsp; Again, make sure the DLL is in the same directory as the rest of your project.</p><p>As for the specifics of calling NLOPT, you&#039;ll need to look at their documentation.&nbsp; If you do run into issues, please feel free to ask here!</p>]]></description>
			<author><![CDATA[null@example.com (jeff)]]></author>
			<pubDate>Tue, 18 Aug 2015 14:16:32 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=2163#p2163</guid>
		</item>
		<item>
			<title><![CDATA[how to include a .dll file in the project?]]></title>
			<link>https://forums.approximatrix.com/viewtopic.php?pid=2162#p2162</link>
			<description><![CDATA[<p>Hi Simply Fortran experts,</p><p>&nbsp; &nbsp; &nbsp;I&#039;m using the NLOPT interface for my project. The package contains a libnlopt-0.dll file, libnlopt-0.def file, and a nlopt.f file. As I&#039;m new to using this type of library, would you suggest how to use them? Should I include them in the project pane, like the regular separate subroutine file?</p><p>Thanks a lot~</p>]]></description>
			<author><![CDATA[null@example.com (wwang328)]]></author>
			<pubDate>Mon, 17 Aug 2015 23:15:07 +0000</pubDate>
			<guid>https://forums.approximatrix.com/viewtopic.php?pid=2162#p2162</guid>
		</item>
	</channel>
</rss>
