SUMMARY: basic ld linker question

From: Charles Vachon <cvachon2_at_mrn.gouv.qc.ca>
Date: Mon, 11 Sep 2000 10:44:05 -0400

Many thanks to:

alan_at_nabeth.cxo.dec.com
Ian Mortimer <ian_at_physics.uq.edu.au>
Lucio Chiappetti <lucio_at_ifctr.mi.cnr.it>
Claudio Tantignone <C_Tantignone_at_sondaarg.com.ar>
Thomas Leitner <tom_at_radar.tu-graz.ac.at>
Nikola Milutinovic <Nikola.Milutinovic_at_ev.co.yu>
Dan Riley <dsr_at_mail.lns.cornell.edu>
"Lampert, Pat" <Pat.Lampert_at_compaq.com>
"Partin, Kevin" <Kevin.Partin_at_COMPAQ.com>
Paul A Sand <pas_at_unh.edu>
Daniel Monjar <dmonjar_at_orgtek.com>

####Original Post####
>
> Hello Tru64 admins,
>
> Trying to compile a C program on Tru64 4.0F.
> Let's say I have a .c program like this:
>
> /*
> * A very basic C program: basic.c
> */
>
> #include <stdio.h>
> int main( int argc, char *argv[] )
> {
> int i;
>
> printf( "program %s has %d arguments:\n", argv[0],argc-1 );
>
> for ( i=1; i < argc; i++ )
> printf( "argv %d: %s\n", i, argv[i] );
>
> return(0);
> }
> /*
> * end of basic C program
> */
>
> I can successfully compile and link with "cc -o basic basic.c".
>
> What stumps me is when I create an object file with "cc -c basic.c",
> which produces a basic.o file, and then I try to link using "ld
> -call_shared -o basic -lc basic.o", I do get a "Unresolved: printf"
from
> ld. Further, if I chmod u+x the resulting (executable) object file
named
> basic and I try to execute it, I do get messages like the following
>
> 10893:./basic: /sbin/loader: Error: Unresolved symbol in
> /usr/shlib/libc.so: __ldr_data
> 10893:./basic: /sbin/loader: Error: Unresolved symbol in
> /usr/shlib/libc.so: __Argc
> 10893:./basic: /sbin/loader: Error: Unresolved symbol in
> /usr/shlib/libc.so: __Argv
> 10893:./basic: /sbin/loader: Fatal Error: this executable has
> unresolvable symbols
>
> Can anyone shed light on this?
####end of Original Post####

Basically, all respondent's answers fall in two categories:

[1]
let cc itself call ld for the linking phase, instead of trying to
manually fire up ld. This is ***strongly recommended***

This can be done in two ways:

cc -o basic basic.c will compile and link all in one stroke

or

cc -o basic.o -c basic will compile basic into object form, followed by
cc -o basic basic.o will link the object file basic.o into an executable
by calling ld

[2]
for the curious mind, use the -v option to cc to see the actual commands
used to perform
the compilation and linking. You could then reproduce the command line
to the ld command as shown in the output of cc -v, but frankly there is
no gain doing so.

Thanks again, this mailing list is GREAT.

--
===============================================
Charles Vachon tel: (418) 627-6355 x2760
  email: cvachon2_at_mrn.gouv.qc.ca
  Administrateur de système
  FRCQ/Ministère des Ressources
  Naturelles du Québec
===============================================
Received on Mon Sep 11 2000 - 14:45:38 NZST

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