Zuczek wrote:
> Jerry Xue wrote:
>> I got the problem. In the makefile, I put the *.o files that are only
>> called by the main program when I specify the dependency. But I forget
>> to put the *.o files that some of the *.o files need.
>> i.e. The following is wrong eventhough the main.f95 only called sub1.o
>> =============================
>> mainprog : main.f95 sub1.o
>> g95 -o mainprog main.f95 sub1.o
>> =============================
>> the right one should be the following, since the sub1.o needs to call
>> sub2.o sub3.o
>> =============================
>> mainprog : main.f95 sub1.o sub2.o sub3.o
>> g95 -o mainprog main.f95 sub1.o sub2.o sub3.o
>> sub1.o : sub1.f95
>> g95 -c sub1.f95
>> sub2.o : sub2.f95
>> g95 -c sub2.f95
>> sub3.o : sub3.f95
>> g95 -c sub3.f95
>> clean:
>> rm -f *.o
>> ============================
>> Richard Maine wrote:
>>
>>> Jerry Xue purdue.edu> wrote:
>>>
>>>
>>>
>>>> Source files, sub1, sub2 and sub3 are subroutine files. I use gnu
>>>> make to
>>>> arrange the compilation. However, I got dependency problem such as:
>>>> --------------------------------------------------------------------------
>>>>
>>>> ub1.f95:(.text+0x27a): undefined reference to `sub2_'
>>>> sub1.f95:(.text+0x27f): undefined reference to `sub3_'
>>>>
>>>
>>> Ok. Yes, with g95 use the -c switch as I showed in order to stop after
>>> making just the .o file. Without the -c switch, the compiler tries to
>>> then link the sub1.o file into an executable, which doesn't work because
>>> it doesn't have all the parts. The -c switch tells it to not do that. It
>>> will make just the sub1.o, which you'll later have to link in with all
>>> the other relevant parts (including a main program, somewhere or other).
>>>
>>>
>>>
> I don't know Fortran 95, I only use Fortran 77. But If a source code of
> my program is divided in many files I use INCLUDE.
Apart from the fact that f77 is valid f95, the INCLUDE statement wasn't part of the
fortran standard until f90. Same for IMPLICIT NONE. They are both common extensions, but
not standard. So, actually, you are using fortran95.
:o)
cheers,
paulv
>
> For example:
> My program files are:
> file1.f, file2.f (Subroutines or functions)
> main.for.(main program)
>
> In file main.for I write
>
> INCLUDE 'file1.f'
> INCLUDE 'file2.f'
>
> PROGRAM main
> IMPLICIT NONE
> ...
>
> STOP
> END
>
> compilation:
>
> e.g. g77 main.for -o main.out
>
> If I use INCLUDE the compiler checks also COMMON dependencies, what is
> very usefull.
>
> Sorry for my english
>
> Zuczek
>
--
Paul van Delst Ride lots.
CIMSS @ NOAA/NCEP/EMC Eddy Merckx