I'm doing something wrong with ar ...

From: <boris_at_gore.afep.cornell.edu>
Date: Fri, 31 Mar 95 15:31:00 -0500

        There seems to be a communication gap between me and the man pages,
having to do with using ar and ld and making object module libraries. The
result is that f2c doesn't work the way the directions say it should. The
short version is this:

main.c:
 #include <stdio.h>
 extern void airnee(char *);
 extern void diddly(char *);
 extern void zponc(char *);
 main() {
   airnee("In function airnee now.\n");
   diddly("In function diddly now.\n");
   zponc("And now we are in function zponc\n");
 }

file1.c:
 #include <stdio.h>
 void airnee(char *str) {
   printf(str);
 }

file2.c:
 #include <stdio.h>
 void diddly(char *str) {
   printf(str);
 }
 void zponc(char *str) {
   printf(str);
 }


Now, assuming the above 3 files, if you do the following:

gore> cc -o main main.c file1.c file2.c
gore> main
In function airnee now.
In function diddly now.
And now we are in function zponc
gore> cc -c file1.c ; cc -c file2.c ; cc -o main main.c file1.o file2.o
gore> main
  [same answer...good]

gore> ar r libmy.a file1.o file2.o ; ranlib libmy.a
ar: Warning: creating libmy.a
s - creating symbol hash table. Wait...
gore> cc -L. -lmy main.c
ld:
Unresolved:
airnee
diddly
zponc
  [obviously isn't going to work]
  [and you get the same answer if you move libmy.a to the /usr/lib directory
   and don't screw around with the -L option]

gore> cc -o main main.c libmy.a
gore> main
  [works as expected]

        The process that the makefiles for f2c function libraries go through is
in analogy to this. Net result is that if the name of the .o file is not
exactly the same as the name of the function contained, or if one file contains
more than one function, the linker can't find it if the library file is
specified as a library, but it can find it if it is fed in along with the source
files. So what did I screw up?
Received on Fri Mar 31 1995 - 15:31:35 NZST

This archive was generated by hypermail 2.4.0 : Wed Nov 08 2023 - 11:53:45 NZDT