<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Approximatrix Forums — Problem with modules]]></title>
	<link rel="self" href="http://forums.approximatrix.com/extern.php?action=feed&amp;tid=896&amp;type=atom" />
	<updated>2023-05-10T20:28:25Z</updated>
	<generator>PunBB</generator>
	<id>http://forums.approximatrix.com/viewtopic.php?id=896</id>
		<entry>
			<title type="html"><![CDATA[Re: Problem with modules]]></title>
			<link rel="alternate" href="http://forums.approximatrix.com/viewtopic.php?pid=4106#p4106" />
			<content type="html"><![CDATA[<p>It sounds like you&#039;re not including <em>both</em> Fortran source files in your project in the second case.&nbsp; The compiler (the linker, to be technically correct), cannot find the definition of the procedure.&nbsp; I&#039;m guessing it is because you are compiling the new Fortran file in the same directory as the original (such that it sees the module&#039;s compiler definition output).&nbsp; However, the linker has no reason to go looking for any particular object file unless the original source file is included in a project.</p><p>Try adding the module&#039;s source file to your project with <em>testmain.f90</em> and everything should work as expected.</p><p>Just a note: <strong>*.mod</strong> files produced by the Fortran compiler do <em>not</em> contain any compiled code.&nbsp; Rather they contain some definitions that the compiler might need when dealing with modules.&nbsp; Object files contain the actual compiled code.</p>]]></content>
			<author>
				<name><![CDATA[jeff]]></name>
				<uri>http://forums.approximatrix.com/profile.php?id=2</uri>
			</author>
			<updated>2023-05-10T20:28:25Z</updated>
			<id>http://forums.approximatrix.com/viewtopic.php?pid=4106#p4106</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Problem with modules]]></title>
			<link rel="alternate" href="http://forums.approximatrix.com/viewtopic.php?pid=4105#p4105" />
			<content type="html"><![CDATA[<p>I&#039;m new to modern Fortran, and to Simply Fortran, which I downloaded a few days ago.&nbsp; Here&#039;s my problem.&nbsp; I built the following module:</p><p>module months<br />&nbsp; &nbsp; implicit none<br />&nbsp; &nbsp; integer, parameter, dimension(12) :: days_per_month = [31,28,31,30,31,30,31,31,30,31,30,31]<br />&nbsp; &nbsp; character(len = 9), parameter, dimension(12) :: month_names = [character(len=9) :: &#039;January&#039;,&#039;February&#039;,&#039;March&#039;,&#039;April&#039;,&#039;May&#039;,&amp;<br />&nbsp; &nbsp; &#039;June&#039;,&#039;July&#039;,&#039;August&#039;,&#039;September&#039;,&#039;October&#039;,&#039;November&#039;,&#039;December&#039;]<br />end module</p><p>The following program compiles and runs:</p><p>program test<br />use months<br />implicit none</p><p>write(*,*) days_per_month(1)</p><p>end program</p><p>but this program won&#039;t even compile:</p><p>program test<br />use months<br />implicit none</p><p>integer :: i</p><p>do i = 1,12<br />write(*,*) days_per_month(i)<br />end do</p><p>end program</p><p>The error message that I get is:</p><p>Generating target.exe<br />build\testmain.o:testmain.f90:(.rdata$.refptr.__months_MOD_days_per_month[.refptr.__months_MOD_days_per_month]+0x0): undefined reference to `__months_MOD_days_per_month&#039;<br />collect2.exe: error: ld returned 1 exit status<br />Error: Last command making (target.exe) returned a bad status<br />Error: Make execution terminated</p><p>* Failed *</p><p>The file is saved as test.f90, and I did not change any compiler defaults.&nbsp; What am I doing wrong??</p>]]></content>
			<author>
				<name><![CDATA[bobsrussell]]></name>
				<uri>http://forums.approximatrix.com/profile.php?id=4123</uri>
			</author>
			<updated>2023-05-10T00:51:54Z</updated>
			<id>http://forums.approximatrix.com/viewtopic.php?pid=4105#p4105</id>
		</entry>
</feed>
