Combining getopt_long () with my own code?

I have my own C project on github. I want to add support with long options using GNU getopt_long()(which has its own git repository). I believe that there are four ways to do this:

  • Use the git submodule .
  • Use git subtree .
  • Import the source of the current (2.22.6) snapshot into my own git repository.
  • Import only source files getopt_long() getopt.c, getopt1.cand gnugetopt.h.

The advantage of 1 and 2 is that I keep track of getopt_long(). The advantages of 3 and 4 are that if the git repository is getopt_long()moved, it will not break my repository, and this is much easier to do.

Is there a recommended “GNU way” for this?

+4
source share
1 answer

After a bit more googl'ing, I found the official GNU answer .

In short, there are two recommended approaches:

Use Gnulib (the "new" way)

Using the command gnulib-tool, one of them imports getoptto compile it as a subset of the GNU library by making several settings for a single file configure.acand Makefile.am.

Use sources getopt_long("old")

Import the sources getopt_long getopt.c, getopt1.cand gnugetopt.huse the macro adl_func_getopt_long.m4to check for existence getopt_longon the platform and, if necessary, compile the imported sources.

+2
source

All Articles