Solved

linking to a FORTRAN library

Posted on 1997-04-04
1
346 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
zeroFront challenge 7 135
data scientists and AI 17 153
sumHeights2  challenge 7 139
bunnyEars2 challenge 6 181
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

732 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