Amiga.org

Amiga computer related discussion => Amiga Software Issues and Discussion => Topic started by: Michele31415 on December 02, 2021, 05:59:28 PM

Title: [SOLVED] Cross-compiled C code won't run
Post by: Michele31415 on December 02, 2021, 05:59:28 PM
I built (with a lot of help from a friend who is a Solaris expert) bebbo's cross-compiler (https://github.com/bebbo/amiga-gcc) on my Sun T4-1.  I compiled helloworld.c:
Code: [Select]
    #include <stdio.h>
    int main()
    {
       // printf() displays the string inside quotation
       printf("Hello, World!");
       return 0;
    }
without errors.  But when I try to run that on my Amiga, it doesn't print anything.  It also doesn't throw an error, it simply returns silently.  So I figured I'd try to run it with gdb (http://aminet.net/dev/gg/gdb-bin.lha) but I can't get that to work either.

Code: [Select]
5.FS3:> FS3:gdb4.16/bin/gdb helloworld
(nothing happens, so I press Return)
object not found
CD failed returncode 20
5.FS3:>
What am I doing wrong?  Is this a path issue, am I missing some libraries, or what?  The helloworld the cross-compiler made is attached (it's not really a zip file, just strip the suffix and run it) if that helps.
Title: Re: Cross-compiled C code won't run
Post by: Thomas on December 02, 2021, 07:12:36 PM

You missed the \n at the end of the string. So it just pushes the string into the output buffer, but the buffer is never flushed.

You could try fflush(stdout) behind the printf. Or just add the \n to the string.

Another possibility would be to use proto/dos.h instead of stdio.h and Printf instead of printf. That way you would bypass the ANSI runtime and call AmigaDOS directly. The output buffer will then belong to the console window rather than the C runtime and the console will print out the buffer when the file handle is closed.
Title: Re: Cross-compiled C code won't run
Post by: Michele31415 on December 02, 2021, 10:01:26 PM
Ah ha.  I added the \n to the string and switched to Printf, compiled on the Sun, copied the output to the Amiga, and it ran fine!  So that's very cool.  I can now compile C code on the Sun using a more recent gcc than I can get for the Amiga natively.  And a lot faster too.  Thanks!