Re: Help! simple compile question



Jerry Xue <zxue@xxxxxxxxxx> wrote:

I have sub1.f95, sub2.f95 and sub3.f95.
sub1.f95 need to call sub2.f95 and sub3.f95. I want to compile sub1.f95
into a object file sub1.o. What's the compiler command that i should
use?

That would depend on what compiler you use, which you neglected to
mention.

But also, the information that you did provide suggests some confusions
somewhere. More details and context would be helpful. You mention that
sub1 calls sub2 and sub3. This might be completely irrelevant or
critical, depending on those unexplained deaitls.

Notably, what is in these files. The file names suggest subroutines, but
you didn't actually say. If they are modules (even modules with
subroutines in them), that makes an important difference.

Assuming that they are not modules, then the fact that sub1 calls sub2
and sub3 is irrelevant.

However, I wonder if you are intending the object code for all of sub1,
sub2, and sub3 to end up in the same object file. Perhaps that's why you
explained the calling relationship. If so, you can't exactly do that
that way, though it is really a matter relating to operating systems and
particular compilers rather than to Fortran. With most current
compilers, each source file makes a separate object file. If you want
the compiled result from multiple source files in a single file, you
either need to combine the source files or, more likely, put the
multiple object files into a single library file; that's pretty much
what libraries are about. But I'm wandering way too far afield in
guessing what you might be asking about instead of what you did actually
ask.

With many compilers, a -c switch tells it to produce an object file,
something like

whatever_your_compiler_is -c sub1.f95

which would seem to be the closest I can come to a literal answer to
your question. However the exact details do depend on the compiler, and
I remain suspicious that there is more to your question than what you
actually asked.

--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
.


Quantcast