Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!batcomputer!rpi!rpi.edu!deven From: deven@pawl.rpi.edu (Deven Corzine) Newsgroups: comp.sys.amiga Subject: Linking without startup code or libraries (Was: Re: Lattice C V5.0 #include bug) Message-ID: Date: 3 Mar 89 06:07:34 GMT References: <92203@sun.uucp> Sender: usenet@rpi.edu Reply-To: shadow@pawl.rpi.edu Distribution: na Organization: RPI Public Access Workstation Lab, Troy NY Lines: 66 In-reply-to: cmcmanis%pepper@Sun.COM's message of 2 Mar 89 22:33:25 GMT In article <92203@sun.uucp> cmcmanis%pepper@Sun.COM (Chuck McManis) writes: >In article shadow@pawl.rpi.edu writes: >>One question - is it possible to create a compiled C module which can >>be linked alone, without being linked to the lib:c.o startup module or >>the lib: libraries? (Clearly the libraries can be ditched if nothing >>in them is used. The question is whether or not you MUST use assembly >>for the startup module...) > >Yes, with Lattice 5.0x it is possible to have nothing but >blink myprog.o to myprog >(which sometimes you can just execute myprog.o if there are no externals >at all) > >Essentially, you will have to define your lib pointers internally and use >the prototypes for direct linkage to the libraries. Can you give me a short simple example that will work for this? Say, the classic "Hello, world!" program? I tried something like this: ----- /* hello.c */ #include #include struct DosLibrary *DOSBase; static char msg[]="Hello, world!\n"; void main() { DOSBase=(struct DosLibrary *) OpenLibrary("dos.library",0); Write(Output(),msg,sizeof(msg)); CloseLibrary((struct Library *) DOSBase); } ----- lc -b -r -v hello.c blink hello.o to hello smallcode smalldata (I'm trying to make the executable as small as possible, but without using assembly.) It compiled and linked without errors, with an executable size of about 100 bytes. But every time I ran it, it caused a GURU. Often GOMF didn't manage to catch it, either. I also tried moving the DOSBase and msg declarations to the end of the file and declaring them as externs in main(), I tried using _main(), (which gave me 604 bytes linking with lib:c.o+hello.o and lib:lc.lib) I tried declaring DOSBase as an extern, but the linker complained that it couldn't resolve _DOSBase (unless I linked with lib:lc.lib) and any time I managed to get it to compile and link, it wouldn't execute. At some point, I think I managed to get it to print something, half garbage. Oh, yes. One more thing - when I have the OpenLibrary() call in, it accesses df0: once, quickly, and then gurus. I think it half-worked (printed , world! or something like that) when I took out the OpenLibrary() and CloseLibrary() calls. Something. Anyway, I couldn't get it to compile, link and run correctly. What am I doing wrong? Do I need to specially define the entry point? (or make the entry function the first function?) Or am I incorrently defining DOSBase? HELP! Deven -- ------- shadow@pawl.rpi.edu ------- Deven Thomas Corzine --------------------- Cogito shadow@acm.rpi.edu 2346 15th Street Pi-Rho America ergo userfxb6@rpitsmts.bitnet Troy, NY 12180-2306 (518) 272-5847 sum... In the immortal words of Socrates: "I drank what?" ...I think.