<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Approximatrix Forums — undefined reference to a subroutine]]></title>
	<link rel="self" href="http://forums.approximatrix.com/extern.php?action=feed&amp;tid=973&amp;type=atom" />
	<updated>2025-01-30T23:58:29Z</updated>
	<generator>PunBB</generator>
	<id>http://forums.approximatrix.com/viewtopic.php?id=973</id>
		<entry>
			<title type="html"><![CDATA[Re: undefined reference to a subroutine]]></title>
			<link rel="alternate" href="http://forums.approximatrix.com/viewtopic.php?pid=4426#p4426" />
			<content type="html"><![CDATA[<p>yes, and tried the f90 extension, some incompatible issues with syntax erros, invalid characters, etc... from those subroutines. Thanks.</p>]]></content>
			<author>
				<name><![CDATA[mt1234]]></name>
				<uri>http://forums.approximatrix.com/profile.php?id=4291</uri>
			</author>
			<updated>2025-01-30T23:58:29Z</updated>
			<id>http://forums.approximatrix.com/viewtopic.php?pid=4426#p4426</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: undefined reference to a subroutine]]></title>
			<link rel="alternate" href="http://forums.approximatrix.com/viewtopic.php?pid=4423#p4423" />
			<content type="html"><![CDATA[<p>Did you put them directly in a file named <em>my_subroutines.mod</em>? <strong>Module files (.mod)</strong> are output by the compiler when it encounters a module statement in a <strong>Fortran source file (.f90, etc.)</strong>.&nbsp; You should <strong>never</strong> be manually creating a <strong>.mod</strong> file.&nbsp; The should just be in a normal Fortran source file, perhaps <em>my_subroutines.f90</em>.</p>]]></content>
			<author>
				<name><![CDATA[jeff]]></name>
				<uri>http://forums.approximatrix.com/profile.php?id=2</uri>
			</author>
			<updated>2025-01-30T21:32:28Z</updated>
			<id>http://forums.approximatrix.com/viewtopic.php?pid=4423#p4423</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: undefined reference to a subroutine]]></title>
			<link rel="alternate" href="http://forums.approximatrix.com/viewtopic.php?pid=4422#p4422" />
			<content type="html"><![CDATA[<p>Thanks. It seems that my problems are just compounding on top of each other. I put the subroutine in question along with 9 or 10 of its dependencies in a module but the main program won&#039;t compile, complaining that File &#039;my_subroutines.mod&#039; opened at (1) is not a GNU Fortran module file. These are subroutines from my old nag library. I&#039;ll keep trying.</p>]]></content>
			<author>
				<name><![CDATA[mt1234]]></name>
				<uri>http://forums.approximatrix.com/profile.php?id=4291</uri>
			</author>
			<updated>2025-01-30T19:02:38Z</updated>
			<id>http://forums.approximatrix.com/viewtopic.php?pid=4422#p4422</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: undefined reference to a subroutine]]></title>
			<link rel="alternate" href="http://forums.approximatrix.com/viewtopic.php?pid=4421#p4421" />
			<content type="html"><![CDATA[<p>The call to <em>G05FEF</em> is indeed undefined. When you declare <em>implicit none</em>, the Fortran compiler will not make any assumptions about anything, especially the signature of a subroutine.&nbsp; You need to do something such that the Fortran compiler knows what <em>G05FEF</em> is.</p><p>The more modern technique would be to place <em>G05FEF</em> in a module:</p><div class="codebox"><pre><code>module my_subroutines
implicit none

    contains

    subroutine G05FEF(a, b, i, s, fail_flag)
        ! body of G05FEF
        ! ...
    end subroutine G05FEF

end module my_subroutines</code></pre></div><p>and then your program would just be:</p><div class="codebox"><pre><code>program test
use my_subroutines
implicit none

Double Precision s(10)
INTEGER IFAIL

Call G05FEF(0.5D0,0.5D0,10,s,IFAIL)

print *, &quot;s is&quot;, s

end program test</code></pre></div><p>If <em>G05FEF</em> is already in a module, make sure you add the module to your program with a <strong>USE</strong> statement.</p><p>Alternatively, you can create an interface block to define the subroutine in your main program:</p><div class="codebox"><pre><code>program test
implicit none

Double Precision s(10)
INTEGER IFAIL

interface
    subroutine G05FEF(a, b, i, s, fail_flag)
    real(kind=8)::a, b
    integer::i, fail_flag
    real(kind=8), dimension(*)::s
end interface

Call G05FEF(0.5D0,0.5D0,10,s,IFAIL)

print *, &quot;s is&quot;, s

end program test</code></pre></div><p>It can be a bit messier, but it allows using legacy routines that aren&#039;t inside a module.</p>]]></content>
			<author>
				<name><![CDATA[jeff]]></name>
				<uri>http://forums.approximatrix.com/profile.php?id=2</uri>
			</author>
			<updated>2025-01-30T14:02:35Z</updated>
			<id>http://forums.approximatrix.com/viewtopic.php?pid=4421#p4421</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[undefined reference to a subroutine]]></title>
			<link rel="alternate" href="http://forums.approximatrix.com/viewtopic.php?pid=4420#p4420" />
			<content type="html"><![CDATA[<p>Just installed Simply Fortran on Windows11, tried to build and run a simple program</p><p>program test<br />implicit none</p><p>Double Precision s(10)<br />INTEGER IFAIL</p><p>Call G05FEF(0.5D0,0.5D0,10,s,IFAIL)</p><p>print *, &quot;s is&quot;, s</p><p>end program test</p><p>that calls some functions and routines, which I added to the project outline. Project building&nbsp; looks fine, with message Generating Makefile ... Okay, * Complete*, but when I compile and run the program file, I get the message undefined reference to &#039;g05fef_&#039;. Any help is greatly appreciated.</p>]]></content>
			<author>
				<name><![CDATA[mt1234]]></name>
				<uri>http://forums.approximatrix.com/profile.php?id=4291</uri>
			</author>
			<updated>2025-01-29T22:05:46Z</updated>
			<id>http://forums.approximatrix.com/viewtopic.php?pid=4420#p4420</id>
		</entry>
</feed>
