简体   繁体   English

AmigaShell C++ (m68k-amigaos-g++) 和命令行 arguments

[英]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).我已经尝试在 Amiga 1200 (Workbench 3.1.4) 上的一个小程序 C++ 中使用命令行 arguments。

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.我使用 bebbo 的交叉编译器 g++ ( m68k-amigaos-g++ )(参见https://github.com/bebbo/amiga-gcc )编译了一个简单的 CLI 应用程序,它只输出 arguments。虽然它在以下情况下工作正常在 Windows 中使用“正常”g++ 编译,它在 Amiga Forever 模拟器和 Amiga 1200 机器的 AmigaShell 中失败。

不工作程序的输出

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.我在一些论坛上发现应该使用预处理器符号__stdargs ,据我所知,它指示编译器处理生成的汇编程序,就好像 function 是使用堆栈上传递的参数调用的,而不是使用寄存器。 Is that correct understanding?这样理解正确吗?

Is the normal that Amiga (and g++) by default use registers and it needs to be overridden for AmigaShell? Amiga(和 g++)默认使用寄存器并且需要为 AmigaShell 覆盖它是正常的吗? I added that to __stdargs to the main() function. Anyway, that did not help.我将它添加到__stdargsmain() function。无论如何,这没有帮助。

Next, I have read, again on some forum, that -mcrt parameter has to be used when compiler output is linked.接下来,我再次在某个论坛上读到,链接编译器 output 时必须使用-mcrt参数。 I have struggled to find the purpose do the parameter.我一直在努力寻找参数的用途。 It seems it specifies which standard C library (similar to glibc ) to be linked?它似乎指定要链接哪个标准 C 库(类似于glibc )? According the Google the following possible variants of the parameter ( -mcrt=nix13 , -mcrt=nix20 , and mcrt=clib2 ) (see eg https://github.com/adtools/libnix ).根据谷歌,参数的以下可能变体( -mcrt=nix13-mcrt=nix20mcrt=clib2 )(参见例如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?唯一运行良好的是nix20nix13没有链接, clib2链接,但该程序在 Amiga 上无法运行。为什么首先我们需要标准的 C 库?

I have used this with -mcrt : m68k-amigaos-g++ args.o -mcrt=nix20 -o args and it finally worked:我已经将它与-mcrt一起使用: m68k-amigaos-g++ args.o -mcrt=nix20 -o args并且它终于起作用了:

最终工作程序的输出

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.您不需要任何MAIN_FNC ,将其删除。 Also don't need to play with -mcrt=xxx .也不需要玩-mcrt=xxx Just link with -noixemul option.只需链接-noixemul选项。

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 ).默认情况下使用/链接ixemul.library (简而言之,非常简单的ixemul.library模拟一些 unix 行为,请参见此处)。 That cause your problem.那会导致你的问题。

More info about -noixemul related to gcc & AmigaOS here: GCC and ixemul.library有关与-noixemul和 AmigaOS 相关的 -noixemul 的更多信息,请访问: GCC 和 ixemul.library

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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