用我自己的代码绑定getopt_long() ?

时间:2022-09-15 18:41:31

I have my own C project on github. I want to add long-option support by using GNU getopt_long() (which has it's own git repository). I believe there are 4 ways I can do this:

我在github上有自己的C项目。我想通过使用GNU getopt_long()(它有自己的git存储库)来添加长选项支持。我相信有四种方法可以做到:

  1. Use a git submodule.
  2. 使用git子模块。
  3. Use a git subtree.
  4. 使用git子树。
  5. Import the source of the current (2.22.6) snapshot into my own git repository.
  6. 将当前快照(2.22.6)的源代码导入我自己的git存储库。
  7. Import only the getopt_long() source files of getopt.c, getopt1.c, and gnugetopt.h.
  8. 只导入getopt的getopt_long()源文件。c,getopt1。c,gnugetopt.h。

The advantage of 1 and 2 is that I track getopt_long(). The advantages of 3 and 4 are that if the git repository of getopt_long() moves, it wont break my repository and it's much simpler to do.

1和2的优点是我跟踪getopt_long()。3和4的优点是,如果getopt_long()的git存储库移动,它不会破坏我的存储库,而且这样做要简单得多。

Is there a recommended "GNU way" to do this?

是否有推荐的“GNU方法”来做这个?

1 个解决方案

#1


2  

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

再用谷歌搜索一下,我找到了官方的GNU答案。

Briefly, there are two recommended approaches:

简单地说,有两种推荐的方法:

Use Gnulib (the "new" way)

Using the gnulib-tool command, one imports getopt to compile it as a subset of the GNU library by making a few tweaks to one's configure.ac and Makefile.am files.

使用gnulib工具命令,通过对配置进行一些调整,导入getopt将其编译为GNU库的一个子集。交流和Makefile。我的文件。

Use getopt_long sources (the "old" way)

Import the getopt_long sources of getopt.c, getopt1.c, and gnugetopt.h and use the adl_func_getopt_long.m4 macro to test for the existence of getopt_long on the platform and compile the imported sources only if necessary.

导入getopt的getopt_long源。c,getopt1。c,gnugetopt。使用adl_func_getopt_long。m4宏用于测试平台上的getopt_long是否存在,并只在必要时编译导入的源代码。

#1


2  

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

再用谷歌搜索一下,我找到了官方的GNU答案。

Briefly, there are two recommended approaches:

简单地说,有两种推荐的方法:

Use Gnulib (the "new" way)

Using the gnulib-tool command, one imports getopt to compile it as a subset of the GNU library by making a few tweaks to one's configure.ac and Makefile.am files.

使用gnulib工具命令,通过对配置进行一些调整,导入getopt将其编译为GNU库的一个子集。交流和Makefile。我的文件。

Use getopt_long sources (the "old" way)

Import the getopt_long sources of getopt.c, getopt1.c, and gnugetopt.h and use the adl_func_getopt_long.m4 macro to test for the existence of getopt_long on the platform and compile the imported sources only if necessary.

导入getopt的getopt_long源。c,getopt1。c,gnugetopt。使用adl_func_getopt_long。m4宏用于测试平台上的getopt_long是否存在,并只在必要时编译导入的源代码。