Giter Club home page Giter Club logo

argtable3's People

Contributors

aegoroff avatar andrew-aladev avatar barracuda156 avatar brainstorm avatar chipweinberger avatar davidzemon avatar fenglc avatar igrr avatar jetbladedevsstuff avatar jhzeba avatar kinddragon avatar myd7349 avatar pengzheng avatar pwpiwi avatar ricksteiling avatar surreylabs avatar tlf30 avatar tomghuang avatar unasuke avatar vincentbernat avatar xiaoxiang781216 avatar yamt avatar zangue avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

argtable3's Issues

cmake find_package error

clone and build argtable3

$ cd argtable3
$ cmake . -L -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=~/devlibs
$ make && make install

build test-argtable3.zip

$ cd test-argtable3
$ cmake . -L -DCMAKE_PREFIX_PATH=~/devlibs
CMake Error at CMakeLists.txt:5 (find_package):
  By not providing "FindArgtable3.cmake" in CMAKE_MODULE_PATH this project
  has asked CMake to find a package configuration file provided by
  "Argtable3", but CMake did not find one.

  Could not find a package configuration file provided by "Argtable3" with
  any of the following names:

    Argtable3Config.cmake
    argtable3-config.cmake

  Add the installation prefix of "Argtable3" to CMAKE_PREFIX_PATH or set
  "Argtable3_DIR" to a directory containing one of the above files.  If
  "Argtable3" provides a separate development package or SDK, be sure it has
  been installed.


-- Configuring incomplete, errors occurred!
See also "/home/xxx/test-argtable3/build/CMakeFiles/CMakeOutput.log".
-- Cache values
Argtable3_DIR:PATH=Argtable3_DIR-NOTFOUND
CMAKE_BUILD_TYPE:STRING=
CMAKE_INSTALL_PREFIX:PATH=/usr/local

Dramatic Build System / Documentation Simplification

You all seem to have thrown out all of the documentation source code as well as the build system that would build a shared library when picking up maintainership. Seems a shame, especially the latter, as it makes it much more of a chore to package it similarly.

Any chance you all might put some of that back or, if I create it, accept a pull request?

Argtable3 differences from argtable2?

Hi there.

I’ve been using argtable2 in projects for years now and I’m a pretty big fan of it. Would you mind telling me what the specific differences (functionality, logic, API, usage, etc.) are between argtable2 and Argtable3? It’s not immediately clear, so it’d help a lot to have an objective understanding of why someone would pick one over the other.

Thank you.

- Jonathan

License-related question

I am a bit confused with the license texts included in the src/getopt.h and src/getopt_long.c files.

What I gather from looking at the files

The src/getopt.h header seems to include a 4-clause BSD license whereas src/getopt_long.c contains:

  • a 2-clause BSD license;
  • another license text which I can't name, but is not the 4-clause BSD.

The important point is: there is no mention of the "3rd clause" of the 4-clause BSD license in src/getopt_long.c.

Also, the LICENSE file at the root of the repository says that the getopt library is distributed by argtable under the 4-clause BSD license.

What I don't understand

Does this mean that:

  • only the header file is distributed under the 4-clause BSD license but not the implementation? (this would seem very strange to me…)
  • the 4-clause BSD text implicitly applies to the src/getopt_long.c file?
  • the content of the LICENSE file takes precedence over the comments in src/getopt_long.c?
  • there is a mistake somewhere?

NB 1. This is related to issue #24. I'm trying to understand which part of argtable exactly I need to remove/replace to get rid of the 4-clause BSD license.

NB 2. I'm no expert in licenses, so I'm sorry if I'm missing a trivial point…

Switch to FreeBSD getopt and getopt_long

The NetBSD getopt library used in argtable3 is licensed under 4-clause BSD, which is (we've been told several times) not compatible to GPL. To resolve this non-technical issue, which does prevent some people using argtable3, we should use the FreeBSD getopt library licensed under 2-clause BSD in the next version.

We can check the following files:

Hosted documentation

I'd like to be able to read the API documentation somewhere on the web, so I don't have to install Sphinx, Breathe, themes, etc. and set up a local webserver. Could it be put up on eg. readthedocs or as Github pages or somewhere similar?

simple config file parsing?

I often find myself often wanting the same set of options defined in a config file as I do on the command line. In other words, use a config file as a stored set of options, which get parsed and override the default settings of the executable, and then can be 'fine-tuned'/overridden by options if provided on the command line.

I guess I could parse the config file into a fake argc/argv array, and feed that to argtable3, but that feels like I'm throwing away information, and potentially messing up the error reporting.

Reasonable enhancement request, or outside the scope of argtablle3?

Minus symbol stripped from negative numbers

I have the following command: set <key> <value>

I want to be able to pass a negative number as the <value> (set some_key -5), however this results in an error (set: invalid option "-?").

Escaping the minus symbol doesn't return an error, but makes the number positive:

> set some_key \-5
Setting value to 5

Wrapping the value in quotes also makes no difference:

> set some_key "\-5"
Setting value to 5

> set some_key "-5"
set: invalid option "-?"

If I make the command set <key> -v|--value <value>, it works fine without the need for escaping.

> set some_key -v -5
Setting value to -5

The only difference I had to make is below:

// Doesn't work
static struct {
    struct arg_str *key = arg_str1(NULL, NULL, "<key>", "Key to update");
    struct arg_str *value = arg_str1(NULL, NULL, "<value>", "Value to set");
    struct arg_end *end = arg_end(2);
} setArgs;


// Works
static struct {
    struct arg_str *key = arg_str1(NULL, NULL, "<key>", "Key to update");
    struct arg_str *value = arg_str1("v", "value", "<value>", "Value to set");  // This line changed
    struct arg_end *end = arg_end(2);
} setArgs;

I can use this as a workaround for the time being, but would prefer to drop the need for -v or --value, if possible, since the command always expects <value> to be present anyways.

For reference: This was initially reported downstream in esp-idf where it was discovered this behavior comes from argtable3 and a reproducible example was put together: espressif/esp-idf#10857

argtable3.c contains a copy of getopt.c from NetBSD under a different license

This should be in a different file, as any project with getopt.c it will also have the functions from argtable3 conflict with it.

Also, it's under a different license to argtable3, and the project's README does not contain the required attribution acknowledgement string.

Ref:

/* $Id: getopt.h,v 1.1 2009/10/16 19:50:28 rodney Exp rodney $ */

/* $Id: getopt_long.c,v 1.1 2009/10/16 19:50:28 rodney Exp rodney $ */

Unicode Support

Seems argtable doesn't handle UTF-8. Have their been any attempts at implementing this?

Argument "?" doesn't work

I'm trying to run the following code:
struct arg_lit *argHelp = arg_lit0("?", "help", "print this help and exit");
But argument "?" just isn't working.

progname -?
progname: invalid option "-?"

With any other argument in place of "?" the code is working. Thus, the error is in "?".

Typo concerning Unicode functions

While debugging some warnings given by argtable, I found that none of the wide character functions were used. I found this: https://github.com/argtable/argtable3/blob/master/argtable3.c#L2977

When I corrected it, the library no longer works unfortunately. I'm currently preparing a patch but in particular, the privhdr structure uses a hard-coded type of const char* which is then passed to a function that takes TRex. If _UNICODE is defined, that's defined as unsigned short.

Looking at the original T-Rex implementation, it's been like that since the beginning, as seen here: https://github.com/kimperator/T-Rex/blob/master/trex.c#L8

Shared library with GCC on Linux

Hello, I'd like to use argtable with my Go lang project but I need the shared library. It would be useful to have a Makefile entry to build it.

index out of bound

In the function;
235 static void arg_parse_tagged(int argc, char** argv, struct arg_hdr** table, struct arg_end* endtable) {
236 struct longoptions* longoptions;
237 char* shortoptions;
238 int copt;
239
240 /printf("arg_parse_tagged(%d,%p,%p,%p)\n",argc,argv,table,endtable);/
241
242 /* allocate short and long option arrays for the given opttable[]. /
243 /
if the allocs fail then put an error msg in the last table entry. /
244 longoptions = alloc_longoptions(table);
245 shortoptions = alloc_shortoptions(table);
246
247 /dump_longoptions(longoptions);/
248
249 /
reset getopts internal option-index to zero, and disable error reporting */
250 optind = 0;
251 opterr = 0;

308 default: {
309 /* getopt_long() found a valid short option /
310 int tabindex = find_shortoption(table, (char)copt);
311 /printf("short option detected from argtable[%d]\n", tabindex);/
312 if (tabindex == -1) {
313 /
should never get here - but handle it just in case /
314 /printf("unrecognised short option %d\n",copt);/
/ This function should not be called since the table index is -1 /
315 arg_register_error(endtable, endtable, copt, NULL);
316 } else {
317 if (table[tabindex]->scanfn) {
318 void
parent = table[tabindex]->parent;
319 int errorcode = table[tabindex]->scanfn(parent, optarg);
320 if (errorcode != 0)
321 arg_register_error(endtable, parent, errorcode, optarg);
322 }
323 }
324 break;
325 }
326 }
327 }

Add doc/examples to explain how to implement sub-commands

We have added API functions to implement sub-commands. We have also added API functions that implement critical data structures, such as hash table, dynamic string, which help to implement sub-commands. However, we've not yet added documentation and examples to explain how to use them.

using argtable in members functions

Hi,
I don't know if this is the right place to post the message.
If it isn't, please redirect me to the correct place.

I'am developping a C++ project on an ESP32.
I'd like to use esp_console + argtable3 in it.
I'm trying to use argtable in my members functions.
To do so, I'm creating callback functions to my members functions with a global pointer.
I'm sure my class is going to be instanced only once so I assume it's ok to create callback functions.

The problem is that argtable isn't giving me back the parameters entered by the user.
It checks for them successfully (number of args and their type) but the data it gives me back is random.
I've tested my code outside of members functions and it works well. But I want to use it inside members functions to access other parts of my object.
Here is my code :

// Pointer for my callback functions
MyClass * _callback;

struct arg_int *argInt;
struct arg_end *endPage;

// My callback function (GLOBAL)
int _setInt(int argc, char *argv[])
{
	return _callback->setInt(argc, argv);
}

// Tab of struct for argtable lib (GLOBAL)
void *setInt_argtable[] =
{
	argInt = arg_int1(NULL, NULL, "<0-12>", "Integer argument"),
	endInt = arg_end(10)
};

// Function I'm calling back
int MyClass::setInt(int argc, char *argv[])
{
	int nerrors = arg_parse(argc,argv,setInt_argtable);
	if (nerrors > 0)
	{
		arg_print_errors(stdout, endPage, "myprog");
		return 0;
	}
	printf("argc = %d\n", argc); 				// argc gives the correct number of args
	printf("argv[0] = %s\n", argv[0]);			// argv[0] gives the correct command name
	printf("argv[1] = %s\n", argv[1]);			// argv[1] gives the correct value
	printf("argInt->ival[0] = %d\n", argInt->ival[0]);	// argInt->ival[0] gives random value
	return 0;
}

void MyClass::main(void)
{
	// Callback pointer initialisation
	_callback = this;

	/* Initializing the console */
	esp_console_config_t console_config
	{
		256,
		8,
		atoi(LOG_COLOR_CYAN),
		0
	};
	ESP_ERROR_CHECK( esp_console_init(&console_config) );

	/* Configure linenoise line completion library */
	/* Enable multiline editing. If not set, long commands will scroll within
	* single line.
	*/
	linenoiseSetMultiLine(1);

	/* Tell linenoise where to get command completions and hints */
	linenoiseSetCompletionCallback(&esp_console_get_completion);
	linenoiseSetHintsCallback((linenoiseHintsCallback*) &esp_console_get_hint);

	/* Set command history size */
	linenoiseHistorySetMaxLen(100);


	esp_console_register_help_command();

	//
	// Feeding my console with argtable parameters
	//

	esp_console_cmd_t consoleCmd;
	consoleCmd.command  = "setInt";
	consoleCmd.func     = &_setInt;
	consoleCmd.help     = "Trying to set a integer argument";
	consoleCmd.argtable = setInt_argtable;
	esp_console_cmd_register(&consoleCmd);

	/* Main loop */
	while(true)
	{
		// Getting command from user
	}
}

The problem seems to be here :
In argatable3.c :
at the end of function static int arg_int_scanfn(struct arg_int *parent, const char *argval) :

if (errorcode == 0)
{
	parent->ival[parent->count++] = val;
	printf("val = %ld\n", val);
	printf("parent->ival[parent->count] = %d\n", parent->ival[parent->count]);
}

The first printf gives me back the correct value but the second one gives me back a random value.

Is my approach of using callback member function good ?
Any idea of what is my problem and how I could solve it ?

Thanks in advance for your answers.

Missing some information about the differences between v2 and v3

I've been using argtable2 for a very long time and recently I've came across with this project. It'd be nice to clarify some points in the docs:

  • What are the differences between v3 and v2 so that they are incompatible?
  • Is the library thread-safe? (I guessed that it's not, since it uses non-thread-safe functions such as getopt()

The amalgamation feature is a +1 feature, so thanks for that!

Table entries with empty glossary strings may displayed.

If I using this line, when I run "foo.exe --help", the file positional argument will displayed.
file = arg_filen(NULL, NULL, "<file>", 1, 1, ""),
If I using this line, when I run "foo.exe --help", the file positional argument will not displayed.
file = arg_filen(NULL, NULL, "<file>", 1, 1, NULL),

I have read the site's tutorial: https://www.argtable.org/tutorial/,
it says "...Table entries with NULL glossary strings are not displayed.",

so I don't know if it is a bug?

Implicit declaration of getenv_s()

cliparser/argtable3.c: In function 'getopt_internal':
cliparser/argtable3.c:1710:3: warning: implicit declaration of function 'getenv_s'; did you mean 'getenv'? [-Wimplicit-function-declaration]
 1710 |   getenv_s(&requiredSize, NULL, 0, "POSIXLY_CORRECT");
      |   ^~~~~~~~
      |   getenv

This is on mingw. I propose to add the usual checks for the availability of this C11 extension:

	if (posixly_correct == -1 || optreset) {
#ifdef _WIN32 && ((defined(__STDC_LIB_EXT1__) && defined(__STDC_WANT_LIB_EXT1__)) || (defined(__STDC_SECURE_LIB__) && defined(__STDC_WANT_SECURE_LIB__)))

		size_t requiredSize;
		getenv_s(&requiredSize, NULL, 0, "POSIXLY_CORRECT");
		posixly_correct = requiredSize != 0;
#else
		posixly_correct = (getenv("POSIXLY_CORRECT") != NULL);
#endif
	}

long glossary line wraps without indentation

/tmp $ ./a.out --help
Usage: util.exe [-v] [--help] [--version] [--level=<n>] [-o myfile] <file> [<file>]...
Demonstrate command-line parsing in argtable3.

  --help                    If the glossary is very long, it will wrap to the next line with no indentation in the following lines. It will 
be great to have a function to format the long line into several lines with indentations!
  --version                 display version info and exit
  --level=<n>               foo value
  -v, --verbose             verbose output
  -o myfile                 output file
  <file>                    input files

If the glossary is very long (--help option for example) , it will wrap to the next line with no indentation in the following lines. It will be great to have a function to format the long line into several lines with indentations!

Issue Linking static lib in Windows

It doesn't matter if I am building for Win32 or 64, when I link against the static lib I am seeing the following errors and warnings and was just curious if this is a know issue or not.

14:10:45 64>argtable3.lib(arg_end.obj) : warning LNK4217: locally defined symbol _fputs imported in function _arg_print_errors
14:10:45 64>argtable3.lib(argtable3.obj) : warning LNK4049: locally defined symbol _fputs imported
14:10:45 64>argtable3.lib(argtable3.obj) : warning LNK4217: locally defined symbol _isspace imported in function _arg_print_formatted_ds
14:10:45 64>argtable3.lib(argtable3.obj) : warning LNK4217: locally defined symbol _strchr imported in function _alloc_longoptions
14:10:45 64>argtable3.lib(getopt_long.obj) : warning LNK4049: locally defined symbol _strchr imported
14:10:45 64>argtable3.lib(argtable3.obj) : warning LNK4217: locally defined symbol _strcspn imported in function _arg_cat_option
14:10:45 64>argtable3.lib(arg_dstr.obj) : warning LNK4217: locally defined symbol ___stdio_common_vsprintf imported in function _arg_dstr_catf
14:10:45 64>argtable3.lib(arg_utils.obj) : warning LNK4217: locally defined symbol ___acrt_iob_func imported in function _dbg_printf
14:10:45 64>argtable3.lib(getopt_long.obj) : warning LNK4049: locally defined symbol ___acrt_iob_func imported
14:10:45 64>argtable3.lib(arg_utils.obj) : warning LNK4217: locally defined symbol ___stdio_common_vfprintf imported in function _dbg_printf
14:10:45 64>argtable3.lib(getopt_long.obj) : warning LNK4049: locally defined symbol ___stdio_common_vfprintf imported
14:10:45 64>argtable3.lib(arg_utils.obj) : warning LNK4217: locally defined symbol _calloc imported in function _xcalloc
14:10:45 64>argtable3.lib(arg_utils.obj) : warning LNK4217: locally defined symbol _free imported in function _merge
14:10:45 64>argtable3.lib(arg_utils.obj) : warning LNK4217: locally defined symbol _malloc imported in function _merge
14:10:45 64>argtable3.lib(arg_utils.obj) : warning LNK4217: locally defined symbol _realloc imported in function _xrealloc
14:10:45 64>argtable3.lib(arg_utils.obj) : warning LNK4217: locally defined symbol _exit imported in function _panic
14:10:45 64>argtable3.lib(arg_utils.obj) : warning LNK4217: locally defined symbol _abort imported in function _panic
14:10:45 64>argtable3.lib(arg_utils.obj) : warning LNK4217: locally defined symbol _getenv imported in function _panic
14:10:45 64>argtable3.lib(getopt_long.obj) : warning LNK4049: locally defined symbol _getenv imported
14:10:45 64>argtable3.lib(getopt_long.obj) : warning LNK4217: locally defined symbol ___stdio_common_vsnprintf_s imported in function _warnx
14:10:45 64>argtable3.lib(getopt_long.obj) : warning LNK4217: locally defined symbol _strncmp imported in function _parse_long_options
14:10:45 64>argtable3.lib(argtable3.obj) : error LNK2019: unresolved external symbol __imp__strncat_s referenced in function _arg_cat_option

Automate amalgamation distribution in the tools/build script

It is tedious and error prone to manually generate amalgamation distribution in both the .tar.gz and .zip formats. I should be able to generate both formats in the tools/build script.

To generate the .zip file:

$ zip -r argtable-x.x.x-amalgamation.zip dist

To generate the .tar.gz file:

$ tar -cvzf argtable-x.x.x-amalgamation.tar.gz dist

I need to figure out how to get the version number within the tools/build script.

When to release the new version?

This patch is important for NuttX(apache/nuttx-apps#559):

commit 01ba528135afc14c9c407b541ab320d01bc17c9b
Author: Tom G. Huang <[email protected]>
Date:   Sat Dec 12 23:33:43 2020 -0800

    feat: Switch to FreeBSD getopt library
    
    Switching to FreeBSD getopt library can resolve two issues:
      1. FreeBSD getopt always uses the 2-Clause BSD, which is compatible
         to GPL. (Although NetBSD has switched to the 2-Clause BSD in
         2008.)
      2. FreeBSD getopt_long provides getopt_long_only, which is critical
         for developers who want to follow the command-line syntax
         convention, which uses a single '-' character for long options.
    
    resolves: #54 #56

@homghuang do you have plan to release a new version in the near furture?

Provide an option to use getopt_long_only

Some popular language runtime or frameworks prefer using a single - character for long options. For example, in Tcl/Tk, all long options start with a single - character and no short options are used.

Currently argtable3 only uses getopt_long to parse arguments. We should provide an API or a compile-time option to make argtable3 use getopt_long_only, so people can use a single - character before long options.

arg_print_formatted_ds does not reset column count when reaching newline

I was redirected here from this issue: espressif/esp-idf#9907

I want to insert some newlines in my text, which the function does print, but doesn't reset the column count when encountering a newline. This results in line wrap to print a newline before reaching 80 characters in that line (or whatever number of characters line wrap is set to). Consequently I get an ugly print for which an example is provided in the above mentioned issue.

Basically this is a feature request to reset column count upon reaching a newline.

Build error on Linux: ‘EOVERFLOW_’ undeclared

steps to reproduce:

cd examples
make

output:

$ make
mkdir -p bin
gcc echo.c ../argtable3.c -I .. -o bin/echo
../argtable3.c: In function ‘arg_int_scanfn’:
../argtable3.c:2256:25: error: ‘EOVERFLOW_’ undeclared (first use in this function)
             errorcode = EOVERFLOW_;
                         ^
../argtable3.c:2256:25: note: each undeclared identifier is reported only once for each function it appears in
Makefile:61: recipe for target 'echo' failed
make: *** [echo] Error 1

ASan errors

The test suite triggers the following Address Sanitizer error:

$ mkdir build
$ cd build
$ CFLAGS="-g -fsanitize=address" cmake ..
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/tmp.zDPAQ7i9CN/argtable3/build
$ make
...
$ CTEST_OUTPUT_ON_FAILURE=1 make test
Running tests...
Test project /tmp/tmp.zDPAQ7i9CN/argtable3/build
    Start 1: test_shared
1/4 Test #1: test_shared ......................***Failed    0.04 sec
=================================================================
==19690==ERROR: AddressSanitizer: global-buffer-overflow on address 0x564055790304 at pc 0x7f2b2a83f901 bp 0x7ffc68f6fef0 sp 0x7ffc68f6fee0
READ of size 1 at 0x564055790304 thread T0
    #0 0x7f2b2a83f900 in arg_extension /tmp/tmp.zDPAQ7i9CN/argtable3/src/arg_file.c:95
    #1 0x7f2b2a83fbff in arg_file_scanfn /tmp/tmp.zDPAQ7i9CN/argtable3/src/arg_file.c:116
    #2 0x7f2b2a84d672 in arg_parse_untagged /tmp/tmp.zDPAQ7i9CN/argtable3/src/argtable3.c:356
    #3 0x7f2b2a84deb2 in arg_parse /tmp/tmp.zDPAQ7i9CN/argtable3/src/argtable3.c:458
    #4 0x56405577a259 in test_argfile_basic_008 /tmp/tmp.zDPAQ7i9CN/argtable3/tests/testargfile.c:198
    #5 0x5640557879d6 in CuTestRun /tmp/tmp.zDPAQ7i9CN/argtable3/tests/CuTest.c:144
    #6 0x564055788a15 in CuSuiteRun /tmp/tmp.zDPAQ7i9CN/argtable3/tests/CuTest.c:282
    #7 0x5640557391eb in RunAllTests /tmp/tmp.zDPAQ7i9CN/argtable3/tests/testall.c:66
    #8 0x564055739290 in main /tmp/tmp.zDPAQ7i9CN/argtable3/tests/testall.c:75
    #9 0x7f2b2a462b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
    #10 0x564055738fe9 in _start (/tmp/tmp.zDPAQ7i9CN/argtable3/build/tests/test_shared+0xdfe9)

0x564055790304 is located 60 bytes to the left of global variable '*.LC15' defined in '/tmp/tmp.zDPAQ7i9CN/argtable3/tests/testargfile.c' (0x564055790340) of size 1
  '*.LC15' is ascii string ''
0x564055790304 is located 0 bytes to the right of global variable '*.LC14' defined in '/tmp/tmp.zDPAQ7i9CN/argtable3/tests/testargfile.c' (0x564055790300) of size 4
  '*.LC14' is ascii string 'foo'
SUMMARY: AddressSanitizer: global-buffer-overflow /tmp/tmp.zDPAQ7i9CN/argtable3/src/arg_file.c:95 in arg_extension
Shadow bytes around the buggy address:
  0x0ac88aaea010: f9 f9 f9 f9 00 06 f9 f9 f9 f9 f9 f9 00 00 00 00
  0x0ac88aaea020: 00 00 02 f9 f9 f9 f9 f9 05 f9 f9 f9 f9 f9 f9 f9
  0x0ac88aaea030: 00 01 f9 f9 f9 f9 f9 f9 00 02 f9 f9 f9 f9 f9 f9
  0x0ac88aaea040: 00 04 f9 f9 f9 f9 f9 f9 00 06 f9 f9 f9 f9 f9 f9
  0x0ac88aaea050: 00 03 f9 f9 f9 f9 f9 f9 00 06 f9 f9 f9 f9 f9 f9
=>0x0ac88aaea060:[04]f9 f9 f9 f9 f9 f9 f9 01 f9 f9 f9 f9 f9 f9 f9
  0x0ac88aaea070: 05 f9 f9 f9 f9 f9 f9 f9 06 f9 f9 f9 f9 f9 f9 f9
  0x0ac88aaea080: 00 f9 f9 f9 f9 f9 f9 f9 00 02 f9 f9 f9 f9 f9 f9
  0x0ac88aaea090: 07 f9 f9 f9 f9 f9 f9 f9 00 02 f9 f9 f9 f9 f9 f9
  0x0ac88aaea0a0: 05 f9 f9 f9 f9 f9 f9 f9 06 f9 f9 f9 f9 f9 f9 f9
  0x0ac88aaea0b0: 07 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==19690==ABORTING

    Start 2: test_static
2/4 Test #2: test_static ......................***Failed    0.03 sec
=================================================================
==19691==ERROR: AddressSanitizer: global-buffer-overflow on address 0x55cc049d6e44 at pc 0x55cc049bc1cb bp 0x7fffa7eb6bb0 sp 0x7fffa7eb6ba0
READ of size 1 at 0x55cc049d6e44 thread T0
    #0 0x55cc049bc1ca in arg_extension /tmp/tmp.zDPAQ7i9CN/argtable3/src/arg_file.c:95
    #1 0x55cc049bc4c9 in arg_file_scanfn /tmp/tmp.zDPAQ7i9CN/argtable3/src/arg_file.c:116
    #2 0x55cc049c9c50 in arg_parse_untagged /tmp/tmp.zDPAQ7i9CN/argtable3/src/argtable3.c:356
    #3 0x55cc049ca478 in arg_parse /tmp/tmp.zDPAQ7i9CN/argtable3/src/argtable3.c:458
    #4 0x55cc049a5de9 in test_argfile_basic_008 /tmp/tmp.zDPAQ7i9CN/argtable3/tests/testargfile.c:198
    #5 0x55cc049b3566 in CuTestRun /tmp/tmp.zDPAQ7i9CN/argtable3/tests/CuTest.c:144
    #6 0x55cc049b45a5 in CuSuiteRun /tmp/tmp.zDPAQ7i9CN/argtable3/tests/CuTest.c:282
    #7 0x55cc04964d7b in RunAllTests /tmp/tmp.zDPAQ7i9CN/argtable3/tests/testall.c:66
    #8 0x55cc04964e20 in main /tmp/tmp.zDPAQ7i9CN/argtable3/tests/testall.c:75
    #9 0x7f652cc09b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
    #10 0x55cc04964b79 in _start (/tmp/tmp.zDPAQ7i9CN/argtable3/build/tests/test_static+0x13b79)

0x55cc049d6e44 is located 60 bytes to the left of global variable '*.LC15' defined in '/tmp/tmp.zDPAQ7i9CN/argtable3/tests/testargfile.c' (0x55cc049d6e80) of size 1
  '*.LC15' is ascii string ''
0x55cc049d6e44 is located 0 bytes to the right of global variable '*.LC14' defined in '/tmp/tmp.zDPAQ7i9CN/argtable3/tests/testargfile.c' (0x55cc049d6e40) of size 4
  '*.LC14' is ascii string 'foo'
SUMMARY: AddressSanitizer: global-buffer-overflow /tmp/tmp.zDPAQ7i9CN/argtable3/src/arg_file.c:95 in arg_extension
Shadow bytes around the buggy address:
  0x0aba00932d70: f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9 00 06 f9 f9
  0x0aba00932d80: f9 f9 f9 f9 00 00 00 00 00 00 02 f9 f9 f9 f9 f9
  0x0aba00932d90: 05 f9 f9 f9 f9 f9 f9 f9 00 01 f9 f9 f9 f9 f9 f9
  0x0aba00932da0: 00 02 f9 f9 f9 f9 f9 f9 00 04 f9 f9 f9 f9 f9 f9
  0x0aba00932db0: 00 06 f9 f9 f9 f9 f9 f9 00 03 f9 f9 f9 f9 f9 f9
=>0x0aba00932dc0: 00 06 f9 f9 f9 f9 f9 f9[04]f9 f9 f9 f9 f9 f9 f9
  0x0aba00932dd0: 01 f9 f9 f9 f9 f9 f9 f9 05 f9 f9 f9 f9 f9 f9 f9
  0x0aba00932de0: 06 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9
  0x0aba00932df0: 00 02 f9 f9 f9 f9 f9 f9 07 f9 f9 f9 f9 f9 f9 f9
  0x0aba00932e00: 00 02 f9 f9 f9 f9 f9 f9 05 f9 f9 f9 f9 f9 f9 f9
  0x0aba00932e10: 06 f9 f9 f9 f9 f9 f9 f9 07 f9 f9 f9 f9 f9 f9 f9
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==19691==ABORTING

    Start 3: test_src
3/4 Test #3: test_src .........................***Failed    0.03 sec
=================================================================
==19692==ERROR: AddressSanitizer: global-buffer-overflow on address 0x564034bb9144 at pc 0x564034b9e227 bp 0x7fff9f261e00 sp 0x7fff9f261df0
READ of size 1 at 0x564034bb9144 thread T0
    #0 0x564034b9e226 in arg_extension /tmp/tmp.zDPAQ7i9CN/argtable3/src/arg_file.c:95
    #1 0x564034b9e525 in arg_file_scanfn /tmp/tmp.zDPAQ7i9CN/argtable3/src/arg_file.c:116
    #2 0x564034babf53 in arg_parse_untagged /tmp/tmp.zDPAQ7i9CN/argtable3/src/argtable3.c:356
    #3 0x564034bac77b in arg_parse /tmp/tmp.zDPAQ7i9CN/argtable3/src/argtable3.c:458
    #4 0x564034b87e45 in test_argfile_basic_008 /tmp/tmp.zDPAQ7i9CN/argtable3/tests/testargfile.c:198
    #5 0x564034b955c2 in CuTestRun /tmp/tmp.zDPAQ7i9CN/argtable3/tests/CuTest.c:144
    #6 0x564034b96601 in CuSuiteRun /tmp/tmp.zDPAQ7i9CN/argtable3/tests/CuTest.c:282
    #7 0x564034b46dd7 in RunAllTests /tmp/tmp.zDPAQ7i9CN/argtable3/tests/testall.c:66
    #8 0x564034b46e7c in main /tmp/tmp.zDPAQ7i9CN/argtable3/tests/testall.c:75
    #9 0x7f8e18385b96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
    #10 0x564034b46bb9 in _start (/tmp/tmp.zDPAQ7i9CN/argtable3/build/tests/test_src+0x13bb9)

0x564034bb9144 is located 60 bytes to the left of global variable '*.LC15' defined in '/tmp/tmp.zDPAQ7i9CN/argtable3/tests/testargfile.c' (0x564034bb9180) of size 1
  '*.LC15' is ascii string ''
0x564034bb9144 is located 0 bytes to the right of global variable '*.LC14' defined in '/tmp/tmp.zDPAQ7i9CN/argtable3/tests/testargfile.c' (0x564034bb9140) of size 4
  '*.LC14' is ascii string 'foo'
SUMMARY: AddressSanitizer: global-buffer-overflow /tmp/tmp.zDPAQ7i9CN/argtable3/src/arg_file.c:95 in arg_extension
Shadow bytes around the buggy address:
  0x0ac88696f1d0: f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9 00 06 f9 f9
  0x0ac88696f1e0: f9 f9 f9 f9 00 00 00 00 00 00 02 f9 f9 f9 f9 f9
  0x0ac88696f1f0: 05 f9 f9 f9 f9 f9 f9 f9 00 01 f9 f9 f9 f9 f9 f9
  0x0ac88696f200: 00 02 f9 f9 f9 f9 f9 f9 00 04 f9 f9 f9 f9 f9 f9
  0x0ac88696f210: 00 06 f9 f9 f9 f9 f9 f9 00 03 f9 f9 f9 f9 f9 f9
=>0x0ac88696f220: 00 06 f9 f9 f9 f9 f9 f9[04]f9 f9 f9 f9 f9 f9 f9
  0x0ac88696f230: 01 f9 f9 f9 f9 f9 f9 f9 05 f9 f9 f9 f9 f9 f9 f9
  0x0ac88696f240: 06 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9
  0x0ac88696f250: 00 02 f9 f9 f9 f9 f9 f9 07 f9 f9 f9 f9 f9 f9 f9
  0x0ac88696f260: 00 02 f9 f9 f9 f9 f9 f9 05 f9 f9 f9 f9 f9 f9 f9
  0x0ac88696f270: 06 f9 f9 f9 f9 f9 f9 f9 07 f9 f9 f9 f9 f9 f9 f9
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==19692==ABORTING

    Start 4: test_amalgamation
4/4 Test #4: test_amalgamation ................***Failed    0.03 sec
=================================================================
==19693==ERROR: AddressSanitizer: global-buffer-overflow on address 0x55ea1bb7ee04 at pc 0x55ea1bb67cdc bp 0x7ffead4c2250 sp 0x7ffead4c2240
READ of size 1 at 0x55ea1bb7ee04 thread T0
    #0 0x55ea1bb67cdb in arg_extension /tmp/tmp.zDPAQ7i9CN/argtable3/dist/argtable3.c:2782
    #1 0x55ea1bb67fda in arg_file_scanfn /tmp/tmp.zDPAQ7i9CN/argtable3/dist/argtable3.c:2803
    #2 0x55ea1bb73719 in arg_parse_untagged /tmp/tmp.zDPAQ7i9CN/argtable3/dist/argtable3.c:5149
    #3 0x55ea1bb73e15 in arg_parse /tmp/tmp.zDPAQ7i9CN/argtable3/dist/argtable3.c:5251
    #4 0x55ea1bb4e1b5 in test_argfile_basic_008 /tmp/tmp.zDPAQ7i9CN/argtable3/tests/testargfile.c:198
    #5 0x55ea1bb5b932 in CuTestRun /tmp/tmp.zDPAQ7i9CN/argtable3/tests/CuTest.c:144
    #6 0x55ea1bb5c971 in CuSuiteRun /tmp/tmp.zDPAQ7i9CN/argtable3/tests/CuTest.c:282
    #7 0x55ea1bb0d147 in RunAllTests /tmp/tmp.zDPAQ7i9CN/argtable3/tests/testall.c:66
    #8 0x55ea1bb0d1ec in main /tmp/tmp.zDPAQ7i9CN/argtable3/tests/testall.c:75
    #9 0x7f457ce7ab96 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x21b96)
    #10 0x55ea1bb0cf29 in _start (/tmp/tmp.zDPAQ7i9CN/argtable3/build/tests/test_amalgamation+0x12f29)

0x55ea1bb7ee04 is located 60 bytes to the left of global variable '*.LC15' defined in '/tmp/tmp.zDPAQ7i9CN/argtable3/tests/testargfile.c' (0x55ea1bb7ee40) of size 1
  '*.LC15' is ascii string ''
0x55ea1bb7ee04 is located 0 bytes to the right of global variable '*.LC14' defined in '/tmp/tmp.zDPAQ7i9CN/argtable3/tests/testargfile.c' (0x55ea1bb7ee00) of size 4
  '*.LC14' is ascii string 'foo'
SUMMARY: AddressSanitizer: global-buffer-overflow /tmp/tmp.zDPAQ7i9CN/argtable3/dist/argtable3.c:2782 in arg_extension
Shadow bytes around the buggy address:
  0x0abdc3767d70: f9 f9 f9 f9 00 06 f9 f9 f9 f9 f9 f9 00 00 00 00
  0x0abdc3767d80: 00 00 02 f9 f9 f9 f9 f9 05 f9 f9 f9 f9 f9 f9 f9
  0x0abdc3767d90: 00 01 f9 f9 f9 f9 f9 f9 00 02 f9 f9 f9 f9 f9 f9
  0x0abdc3767da0: 00 04 f9 f9 f9 f9 f9 f9 00 06 f9 f9 f9 f9 f9 f9
  0x0abdc3767db0: 00 03 f9 f9 f9 f9 f9 f9 00 06 f9 f9 f9 f9 f9 f9
=>0x0abdc3767dc0:[04]f9 f9 f9 f9 f9 f9 f9 01 f9 f9 f9 f9 f9 f9 f9
  0x0abdc3767dd0: 05 f9 f9 f9 f9 f9 f9 f9 06 f9 f9 f9 f9 f9 f9 f9
  0x0abdc3767de0: 00 f9 f9 f9 f9 f9 f9 f9 00 02 f9 f9 f9 f9 f9 f9
  0x0abdc3767df0: 07 f9 f9 f9 f9 f9 f9 f9 00 02 f9 f9 f9 f9 f9 f9
  0x0abdc3767e00: 05 f9 f9 f9 f9 f9 f9 f9 06 f9 f9 f9 f9 f9 f9 f9
  0x0abdc3767e10: 07 f9 f9 f9 f9 f9 f9 f9 00 f9 f9 f9 f9 f9 f9 f9
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07 
  Heap left redzone:       fa
  Freed heap region:       fd
  Stack left redzone:      f1
  Stack mid redzone:       f2
  Stack right redzone:     f3
  Stack after return:      f5
  Stack use after scope:   f8
  Global redzone:          f9
  Global init order:       f6
  Poisoned by user:        f7
  Container overflow:      fc
  Array cookie:            ac
  Intra object redzone:    bb
  ASan internal:           fe
  Left alloca redzone:     ca
  Right alloca redzone:    cb
==19693==ABORTING


0% tests passed, 4 tests failed out of 4

Total Test time (real) =   0.14 sec

The following tests FAILED:
	  1 - test_shared (Failed)
	  2 - test_static (Failed)
	  3 - test_src (Failed)
	  4 - test_amalgamation (Failed)
Errors while running CTest
Makefile:94: recipe for target 'test' failed
make: *** [test] Error 8
$ git log -1
commit e58754ed716542a54f75a9c9ba5c85a057b8ea00 (HEAD -> master, origin/master, origin/HEAD)
Author: Tom G. Huang <[email protected]>
Date:   Sun Nov 24 12:03:02 2019 -0800

    doc: How to get details when unit tests go wrong
$ cc --version
cc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ uname -rms
Linux 5.0.0-23-generic x86_64
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 18.04.4 LTS
Release:        18.04
Codename:       bionic

argtable3.c:493:5: warning: implicit declaration of function ‘warnx’

when compiled with -std=c11 on linux, the following error reports:

compiles without warning

<(((º> gcc -c argtable3.c -o argtable3.o

compiles with warning

<(((º> gcc -std=c11 -c argtable3.c -o argtable3.o
argtable3.c: In function ‘parse_long_options’:
argtable3.c:493:5: warning: implicit declaration of function ‘warnx’ [-Wimplicit-function-declaration]
warnx(ambig, (int)current_argv_len,
^

Compilation error with optimization on ARM

I got this error while compiling with -Wall on an ARM target:

../../src/Backup/src/argtable3.c: In function ‘trex_compile’:
../../src/Backup/src/argtable3.c:347:11: error: variable ‘ret’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Werror=clobbered]
     void* ret = malloc(size);

The problem in in the function trex_compile which uses setjmp() to handle errors, on posix man setjmp states:

       The  compiler  may  optimize variables into registers, and longjmp() may restore the values of
       other registers in addition to the stack pointer and program counter.  Consequently, the  val‐
       ues of automatic variables are unspecified after a call to longjmp() if they meet all the fol‐
       lowing criteria:

       •  they are local to the function that made the corresponding setjmp() call;

       •  their values are changed between the calls to setjmp() and longjmp(); and

       •  they are not declared as volatile.

I've not found any way to satisfy the above requirements without changing the function signature, but I've solved the error disabling optimizations locally, this way the compiler (gcc 9.2) put the variable on the stack and the error get resolved.

At the function declaration:

TREX_API TRex* trex_compile(const TRexChar* pattern, const TRexChar** error, int flags) __attribute__((optimize(0)));  

I'm filing an issue because maybe someone has a better idea.

Specifying array of delimiter separated values

I don't see a way to specify multiple values at once for a parameter. For instance, I think -p 44,55,66 is a bit more clear than -p 44 -p 55 -p 66 and perhaps a bit easier to parse. Since we know the type of the argument before hand, perhaps this can be specific to integers, doubles, etc. to avoid complicating the parsing of string values as well (where a comma or similar might be a valid part of the value string).

Provide public API for customizing output

@hzeba has provided a great example, which shows how to customize glossary and error message output format. However, the example has to use several private functions (such as arg_cat_optionv() and arg_print_formatted_ds()) to customize the output. It means that Argtable3 doesn't provide enough public API for this purpose.

We need to carefully open several private functions, so that developers can have enough public interface to customize their output.

What are the arg_key functions()?

Howdy. Am studying the documentation on argtable2 and see some argument constructors I am not following and haven't been able to find documentation upon. Specifically:

  • arg_key0
  • arg_key1
  • arg_keyn

Would it be possible to have these explained and when/where I might want to use such?

Implicit declaration of function 'vsnprintf'

When compiling the argtable3.c file produced by tools/build dist (as of fe70fd5) with gcc version 10.2.0, I get the following warning:

$ cc --version
cc (GCC) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ cc -Wall -Wextra -pedantic -ansi -c argtable3.c
argtable3.c: In function 'arg_dstr_catf':
argtable3.c:1104:13: warning: implicit declaration of function 'vsnprintf'; did you mean 'vsprintf'? [-Wimplicit-function-declaration]
 1104 |         r = vsnprintf(buff, n + 1, fmt, arglist);
      |             ^~~~~~~~~
      |             vsprintf

From the man page, vsnprintf seems to only be available starting from C99

licensing(

Hi

I tried to use argtable3 in proxmark3 project and noticed that getopt not compatible with GPL v2:

There is getopt with 4-clause BSD license (old BSD licence) which included 3rd clause.
3rd clause is not compatible with GPL licenses(

May you change this getopt to getopt from freebsd which have simplified BSD license?
here: https://github.com/freebsd/freebsd/blob/master/include/getopt.h

clang vs gcc attributes

Greetings:

When I compile under LLVM 11 and 12 I receive the following warning.

warning: unknown attribute 'optimize' ignored [-Wunknown-attributes]
TREX_API TRex* trex_compile(const TRexChar* pattern, const TRexChar** error, int flags) __attribute__((optimize(0)));

My current "fix" for this is below.

#ifdef __clang__
TREX_API TRex* trex_compile(const TRexChar* pattern, const TRexChar** error, int flags) __attribute__((optnone));
#else
#ifdef __GNUC__
TREX_API TRex* trex_compile(const TRexChar* pattern, const TRexChar** error, int flags) __attribute__((optimize(0)));
#else
TREX_API TRex* trex_compile(const TRexChar* pattern, const TRexChar** error, int flags);
#endif
#endif

Could something like this be merged? Thank you for your help with this.

Kind regards,
Anthony

Parsing issue: trailing backslash with spaced paths

System: Windows

When passing an string argument to a command line application that ends with backslash, the trailing quote is escaped.

Reproducible by simply having an arg_filen argument that takes in a file path. Multiple arg_filen parameters with multiple quoted paths are not parsable and results in an error (example test-path.zip)

single file

input: test.exe "C:\test folder\"
path1 = C:\test folder"

multiple files

input: test.exe "C:\test folder\" "C:\test folder2\"
path1 = C:\test folder" C:\test
path2 = folder2"

Let me know if you require additional information.

Enhance CMake scripts to take advantage of vcpkg's manifest mechanism

The latest vcpkg release allows us to specify dependencies in the manifest file (vcpkg.json) in the project root directory. Since vcpkg already includes the 3.1.5 release in its ports, in theory developers should be able to add vcpkg.json to the root directory to add the argtable3 library:

{
    "name": "versions-test",
    "version": "1.0.0",
    "dependencies": [
        {
            "name": "fmt",
            "version>=": "7.1.3#4"
        }, 
        {
            "name": "argtable3",
            "version>=": "3.1.5"
        }, 
        "zlib"
    ],
    "builtin-baseline": "a3db16a4475b963cacf0260068c497fb72c8f3c0"
}

And include the dependencies in the root CMakeLists.txt:

cmake_minimum_required(VERSION 3.18)

set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_SOURCE_DIR}/deps/vcpkg/scripts/buildsystems/vcpkg.cmake
 CACHE STRING "Vcpkg toolchain file")
set(VCPKG_TARGET_TRIPLET x64-windows-static CACHE STRING "Vcpkg target triplet")

project(versionstest CXX)

add_executable(main main.cpp)

find_package(ZLIB REQUIRED)
find_package(fmt CONFIG REQUIRED)
find_package(Argtable3 CONFIG REQUIRED)
target_link_libraries(main PRIVATE ZLIB::ZLIB fmt::fmt argtable3_static)
set_property(TARGET main PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

In the CMakeLists.txt file above, we specify that we want to use the x64-windows-static triplet, which means that we want to use the static library of the dependencies.

Now we can run the following commands to download the dependencies and build the project:

$ mkdir build
$ cd build
$ cmake ..
$ cmake --build .

However, CMake will show the following error messages:

CMake Error at build/vcpkg_installed/x64-windows-static/share/argtable3/Argtable3Config.cmake:76 (message):
  The imported target "argtable3" references the file

     "D:/Projects/testvcpkg/build/vcpkg_installed/x64-windows-static/debug/bin/argtable3.dll"

  but this file does not exist.  Possible reasons include:

  * The file was deleted, renamed, or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and contained

     "D:/Projects/testvcpkg/build/vcpkg_installed/x64-windows-static/share/argtable3/Argtable3Config.cmake"

  but not all the files it references.

Call Stack (most recent call first):
  build/vcpkg_installed/x64-windows-static/share/argtable3/vcpkg-cmake-wrapper.cmake:1 (_find_package)
  deps/vcpkg/scripts/buildsystems/vcpkg.cmake:815 (include)
  CMakeLists.txt:15 (find_package)

The root cause of this problem is that argtable3 builds and installs both the dynamic and static libraries at the same time, while vcpkg expects argtable3 to install one of them. We need to modify how the CMake scripts export targets and install export files, so it won't conflict with vcpkg's design.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.