Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to cpp-optparse #1

Merged
merged 2 commits into from Mar 24, 2015
Merged

Fixes to cpp-optparse #1

merged 2 commits into from Mar 24, 2015

Conversation

benoit-leveau
Copy link

Default values for options can be set either with a string or another type because Option::set_default() has a templated version. OptionParser::set_defaults() only had a string version, so I added a templated one as well so we can do:

OptionParser parser = OptionParser();
parser.add_option("--option1").action("store").type("int").set_default("1");
parser.add_option("--option2").action("store").type("int").set_default(1);
parser.set_defaults("options1", "640");
parser.set_defaults("option2", 640); // now works

Default values for options inside an OptionGroup were not previously working:

OptionParser parser = OptionParser();
OptionGroup group = OptionGroup(parser, "Size Options", "Image Size Options.");
group.add_option("-w", "--width").action("store").type("int").set_default(640).help("default: %default");
group.add_option("-h", "--height").action("store").type("int").help("default: %default");
group.set_defaults("height", 480);
parser.add_option_group(group);

Values& parse_options = parser.parse_args(argc, argv);
std::cout << "width: " << int(parse_options.get("width")) << std::endl;
std::cout << "height: " << int(parse_options.get("height")) << std::endl;

would print:

width: 0
height: 0

When looking for default values, we now browse the OptionGroup list and look for default values in the options and at the OptionGroup level.
It now correctly prints:

width: 640
height: 480

Benoit added 2 commits March 16, 2015 15:18
…he one set for Option::set_default.

Example: parser.set_defaults("width", 640);
weisslj pushed a commit that referenced this pull request Mar 24, 2015
@weisslj weisslj merged commit 278e8c0 into weisslj:master Mar 24, 2015
@weisslj
Copy link
Owner

weisslj commented Mar 24, 2015

Thanks!

weisslj added a commit that referenced this pull request Mar 24, 2015
@alonsojr1980
Copy link

Friends, I'm having trouble using OptionParser.h in a VS Community 2013 project. The compile error is:

Error 1 error LNK2019: unresolved external symbol "public: __cdecl optparse::OptionParser::OptionParser(void)" (??0OptionParser@optparse@@qeaa@XZ) referenced in function main D:\AREA_TRABALHO_CGM\SISTEMAS\CGM_IMAGE_TOOLS\CgmImageTools\main.obj CgmImageTools

Any tips? Thanks!

@benoit-leveau
Copy link
Author

The error you're getting basically means that your project can't find the
actual code of OptionParser. You've probably only added the header through
an include, but not the cpp file.

So, you either need to:

  1. add OptionParser.cpp to your project as well
    or
  2. link your project with a OptionParser library that you would compile in
    a separate project (this project would contain only OptionParser.cpp/.h)

Option 1 will be easier and is just a matter of adding the file to your
visual studio project.

On Mon, Jul 13, 2015 at 8:45 PM, alonsojr1980 notifications@github.com
wrote:

Friends, I'm having trouble using OptionParser.h in a VS Community 2013
project. The compile error is:

Error 1 error LNK2019: unresolved external symbol "public: __cdecl
optparse::OptionParser::OptionParser(void)" (??0OptionParser@optparse
@@qeaa@XZ) referenced in function main
D:\AREA_TRABALHO_CGM\SISTEMAS\CGM_IMAGE_TOOLS\CgmImageTools\main.obj
CgmImageTools

Any tips? Thanks!


Reply to this email directly or view it on GitHub
#1 (comment).

@alonsojr1980
Copy link

Thank you! I'm new to c++ and appreciate your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants