bebbo / libnix

libnix (v4): a C link library for AmigaOS/m68k
14 stars 9 forks source link

Undefined reference to `optopt' using -mcrt=nix20 #40

Closed hologenics closed 3 years ago

hologenics commented 3 years ago

Unsure if this is supported or an overlooked edge case... .

Using getopts with -mcrt=nix20

Code Example (does not do anything but demos the linker issue).

Compile with

amiga-g++ -mcrt=nix20 test.cpp

#include <stdio.h>
#include <unistd.h>

int main(int argc, char ** args)
{
    // Start from parsing command line arguments
  while(true) {
      int c = getopt(argc, args, "?hCLc:s:X");
    switch(c) 
    {
    case -1:
      goto args_done;

    case 's':
      break;

    case 'X':
        break;

    case '?':
    case 'h':
    default:
        if (optopt == 'c')
        {
            printf("Unnown Cables\n");
            exit(1);
        }
    }
  }
 args_done:
  return 0;
}

What happens...

/opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/../../../../m68k-amigaos/bin/ld: /tmp/ccjgC7wT.o:/tmp/ccjgC7wT.o:(.text+0x166): undefined reference to `optopt'

Possibly unpublished extern int optopt?

hologenics commented 3 years ago

Confirmed fixed.