Why won't this Fortran90 program compile?

What's wrong with this Fortran90 program? I can't get it to compile...
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MarkLoveExExAuthor Commented:
I get this error:
JohnBusiness Consultant (Owner)Commented:
It has been a very long time since I have used Fortran, but the error says you have not linked in the modules you need to successfully compile. When you compile any program, there is an opportunity to link in canned (pre-programmed) routines. Have you done this?
Joe Winograd, Fellow&MVEDeveloperCommented:
What commands are you using to compile it and/or link it with the necessary libraries to generate an executable? For example, to compile it, you'll use something like this:

gfortran -c HEtoGrib2.f90

To create an executable, you'll use something like this:

gfortran -o ExecutableName object1.o object2.o object3.o

You'll have as many objectN.o libraries as necessary — that's where your functions and subroutines called by HEtoGrib2 will be located (lenstr, stoi, rdxmrg, baopenw, gribcreate, addgrid, addfield, gribend, wryte). Regards, Joe

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

MarkLoveExExAuthor Commented:
I compiled the HEtoGrib2.f90 program using the following command:

gfortran -c HEtoGrib2.f90

which seemed to compile without error. It produced a file called HEtoGrib2.o

I then ran the following:

HEtoGrib2.o /home/oper/practice3/ serfc_xmrg1119201506z /home/oper/practice3/ mygrib.grb

but I got the following error:

HEtoGrib2.o: HEtoGrib2.o: cannot execute [Exec format error]

Do you know what I'm doing wrong? Maybe my input file is not compatible...
Joe Winograd, Fellow&MVEDeveloperCommented:
I'm not knowledgeable in Unix/Linux, but my guess is that your command line needs to include the object code files (object1.o, object2.o, etc.) that have all the functions and subroutines that you're calling (lenstr, stoi, rdxmrg, baopenw, gribcreate, addgrid, addfield, gribend, wryte). It makes sense that the compile is successful — it is the linking into an executable that is failing because it can't find the object code files needed. Regards, Joe
>> I then ran the following:
>>  HEtoGrib2.o /home/oper/practice3/ serfc_xmrg1119201506z /home/oper/practice3/ mygrib.grb
HEtoGrib2.o is an object module, not an executable, so you cannot run it.

>> gfortran -c HEtoGrib2.f90
I think the -c option means to create an object module and do not continue to create an executable.

>> call baopenw(lunout,trim(filename),ierr)
>> HEtoGrib2.f90:(.text+0x337e): undefined reference to `baopenw_'
There is a subroutine baopenw that must be defined somewhere. In what file did you define it?
Joe Winograd, Fellow&MVEDeveloperCommented:
> I think the -c option means to create an object module and do not continue to create an executable.

Yes, that's correct. You need to use the -o option to create the executable. See my earlier post that discusses it:

Regards, Joe
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.