简体   繁体   中英

AmigaShell C++ (m68k-amigaos-g++) and command line arguments

I have tried working with the command line arguments in a small C++ program on Amiga 1200 (Workbench 3.1.4).

I have compiled with the use of bebbo's cross-compiler g++ ( m68k-amigaos-g++ ) (see https://github.com/bebbo/amiga-gcc ) a simple CLI app that just outputs the arguments. While it works fine when compiled with 'normal' g++ in Windows, it failed in AmigaShell in Amiga Forever emulator and Amiga 1200 machine as well.

不工作程序的输出

I have found on some forums that the preprocessor symbol __stdargs should be used, which as I understand instructs the compiler to handle the generated assembler as if the function was called with the parameters passed on stack and not with the use of registers. Is that correct understanding?

Is the normal that Amiga (and g++) by default use registers and it needs to be overridden for AmigaShell? I added that to __stdargs to the main() function. Anyway, that did not help.

Next, I have read, again on some forum, that -mcrt parameter has to be used when compiler output is linked. I have struggled to find the purpose do the parameter. It seems it specifies which standard C library (similar to glibc ) to be linked? According the Google the following possible variants of the parameter ( -mcrt=nix13 , -mcrt=nix20 , and mcrt=clib2 ) (see eg https://github.com/adtools/libnix ).

The only one that works fine was nix20 ( nix13 did not link and clib2 linked, but the program did not work on Amiga. Why in a first-place we need the standard C library?

I have used this with -mcrt : m68k-amigaos-g++ args.o -mcrt=nix20 -o args and it finally worked:

最终工作程序的输出

Can anybody describe to me as a newbie a bit more background details of all this?

Here is my test program:

#include <iostream>
using std::cout;

#if defined (__AMIGA__)
    #define MAIN_FNC __stdargs
#else
    #define MAIN_FNC
#endif

MAIN_FNC int main( int argc, char *argv[] )
{
    cout << "Arguments count:" << argc << " \n";
    for ( int i = 0; i < argc; i ++ )   
        cout << i << ". [" << argv[i] << "]\n";

    return 0;
}

You don't need any MAIN_FNC , remove it. Also don't need to play with -mcrt=xxx . Just link with -noixemul option.

m68k-amigaos-g++ args.o -noixemul -o args

By default ixemul.library is used/linked (in short and very simply the ixemul.library emulate some unix behavior, see here ). That cause your problem.

More info about -noixemul related to gcc & AmigaOS here: GCC and ixemul.library

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM