• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 361
  • Last Modified:

linking to a FORTRAN library

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
birkedal
Asked:
birkedal
1 Solution
 
dominusCommented:
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now