Solved

linking to a FORTRAN library

Posted on 1997-04-04
1
331 Views
Last Modified: 2013-12-26
I have been trying to create a *.a library from many FORTRAN mathematical subroutines.  I don't think I'm doing it right because when I try to link it to a C program I'm compiling, I get the following error message:
/bin/ld : Unsatisfied symbols:
   ddriv1 (code)
*** Error code 1

ddriv1 is the subroutine that my C program needs from the library.  I'm very new at this, so please don't assume much technical knowledge.  I'm using an HP 9000-700 running HP-UX 9.0, HP FORTRAN 9000, and HP C.  Any help would be greatly appreciated.
0
Comment
Question by:birkedal
1 Comment
 

Accepted Solution

by:
dominus earned 100 total points
ID: 1292517
Part I:

First, you need to make sure you built the .a ilbrary properly.  try `nm library.a' and make sure that the output mentions the `ddrv1' function.  If not, come back here and say what commands you used to compile and build the library.

Part II:

1. The fortran and C compilers may have different conventions about the names that they store the objects under in the .o file.  Here's what you can do:

2. Create a ddriv.c file that just says
      int ddriv1(void) { return 1; }
and compile it into a .o file.

3. Use `nm' on the .o file to find out what the symbol name
is in the .o file. Let's say it is `_ddriv1', which is typical.
Now you know what the C compiler is expecting to call when it compiles your C code.

4. Use `nm' on the fortran `.a' library to see what the symbol names are there.  Perhaps you'll see, for example, that the fortran version of `ddriv1' compiled into a symbol named
`ddriv1' (no leading underscore) or `DDRIV1'.  Now you know how
the ortran compiler compiles the function.

5. If the C versions and Fortran versions are the same, come back here and show us the exact commands you use to compile and to attempt to link the program.  If not:

6. Adjust the fortran code and/or the C calling code appropriately, so that the symbol name generated by the fortran compiler is the same as the one that the C compiler was expecting.  

For example, if the fortran compile compiles `ddriv1' as `DDRIV1', when the C compiler was expecting it to be `_ddriv1',
then you should change the name of the fortran function
to `_ddrv1' and fix up the C code to call `DDRV1' instead of `ddriv1'.  Then the compiled symbol names will match.

7. Alternatively, there may be a command-line option to the fortran compiler to tell it to make the symbol names different.

-dominus
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now