From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <96868339218790.tru64-unix-managers.marc@archive.invalid> From: Charles Vachon Date: Mon, 11 Sep 2000 14:44:05 +0000 To: tru64-unix-managers Subject: SUMMARY: basic ld linker question X-MARC-Message: https://marc.info/?l=tru64-unix-managers&m=96868339218790 Many thanks to: alan@nabeth.cxo.dec.com Ian Mortimer Lucio Chiappetti Claudio Tantignone Thomas Leitner Nikola Milutinovic Dan Riley "Lampert, Pat" "Partin, Kevin" Paul A Sand Daniel Monjar ####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 > int main( int argc, char *argv[] ) > { > int i; > > printf( "program %s has %d arguments:\n", argv[0],argc-1 ); > > for ( i=3D1; 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. -- =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Charles Vachon tel: (418) 627-6355 x2760 email: cvachon2@mrn.gouv.qc.ca Administrateur de syst=E8me FRCQ/Minist=E8re des Ressources Naturelles du Qu=E9bec =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D