Welcome, Guest. Please login or register.
Amiga Kit Amiga Store Iridium Banner AMIStore App Store A1200/A600 4xIDE Interface

AuthorTopic: [SOLVED] Cross-compiled C code won't run  (Read 592 times)

0 Members and 1 Guest are viewing this topic.

Offline Michele31415

[SOLVED] Cross-compiled C code won't run
« 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.
« Last Edit: December 02, 2021, 10:02:22 PM by Michele31415 »
Active: B2000 4.4, A2630, GVP 2000 HC+8, DKB 2632, SCSI2SD, Gotek, Deneb USB, XSurf 3cc, CD ROM, Megachip 2000, ECS Agnus, Denise, OS 3.9, GVP Spectrum EGS 28/24, Silicon Springs GOMF
Retired: A2088, 8-Up, A2090a, Oktagon 2008, Kitchen Sync
Busted: A2091
 

Offline Thomas

Re: Cross-compiled C code won't run
« Reply #1 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.
 
The following users thanked this post: Michele31415

Offline Michele31415

Re: Cross-compiled C code won't run
« Reply #2 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!
Active: B2000 4.4, A2630, GVP 2000 HC+8, DKB 2632, SCSI2SD, Gotek, Deneb USB, XSurf 3cc, CD ROM, Megachip 2000, ECS Agnus, Denise, OS 3.9, GVP Spectrum EGS 28/24, Silicon Springs GOMF
Retired: A2088, 8-Up, A2090a, Oktagon 2008, Kitchen Sync
Busted: A2091