Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uflorida!ukma!xanth!mcnc!rti!sas!toebes From: toebes@sas.UUCP (John Toebes) Newsgroups: comp.sys.amiga Subject: Re: Linking without startup code or libraries Message-ID: <971@sas.UUCP> Date: 16 Mar 89 18:40:25 GMT References: <92203@sun.uucp> <92710@sun.uucp> Reply-To: toebes@sas.UUCP (John Toebes) Distribution: na Organization: SAS Institute Inc, Cary NC Lines: 48 In article <92710@sun.uucp> cmcmanis@sun.UUCP (Chuck McManis) writes: >In article <92203@sun.uucp> I wrote: >> Yes, with Lattice 5.0x it is possible to have nothing but >> blink myprog.o to myprog >This is correct. >> Essentially, you will have to define your lib pointers internally and use >> the prototypes for direct linkage to the libraries. > >Then in a followup article shadow@pawl.rpi.edu writes: >> Can you give me a short simple example that will work for this? Say, >> the classic "Hello, world!" program? I tried something like this: > >To which I reply "Certainly" and here it is : > ... example deleted ... Actually this question has come up quite frequently and there turns out to be an even smaller solution that is made possible with 5.0 that has the additional advantage of being RESIDENTABLE! #include #include #include #include #define MSG(f,s) Write(f,s,strlen(s)) void tinyhello() { struct DosLibrary *DOSBase; /* NOTE it is a local variable */ if ((DOSBase = (struct DosLibrary *)OpenLibrary("dos.library",0)) != NULL) { MSG(Output(), "Hello World\n"); CloseLibrary((struct Library *)DOSBase); } } Compile this with LC -cs -v tinyhello blink tinyhello.o Note that if you use the -cs option, the strings will be put into the code section automatically. Since the library base for the call is a local variable (a trick added under 5.0) and the strings are accessed pc-relative, there is no need to have A4 set up. This trick is used in POPCLI 4 and also in the Avail program on the Lattice diskettes. Enjoy. >--Chuck McManis >uucp: {anywhere}!sun!cmcmanis BIX: cmcmanis ARPAnet: cmcmanis@sun.com >These opinions are my own and no one elses, but you knew that didn't you.