Add in the CMD library
The CMD library is a helpful little library which:
Makes it easier to add command line arguments to your command line application.
Adds in support for the flags that support our tracing system.
Also prints out help arguments
To make the video I altering the main.cpp file to have some extra lines to use the CMD library:
//---------------------------------------------------------------------------
// Copyright (C) 1997-2020 iNTERFACEWARE Inc. All Rights Reserved
//
// Module: main.cpp
//
// Description:
//
// An example command line app
//
// Author: Eliot Muir
// Date: Thu 01/15/2004
//---------------------------------------------------------------------------
#include <COL/COLostream.h>
#include <COL/COLerror.h>
#include <stdlib.h>
#include <CMD/CMDlineParser.h>
int main(int argc, const char** argv) {
try{
CMDlineParser Parser;
Parser.parseArgs(argc, argv);
if (Parser.parsingErrorsPresent(COLcout)){
Parser.showUsage(COLcout);
return EXIT_FAILURE;
}
COLcout << "Hello world!" << newline;
return EXIT_SUCCESS;
} catch (COLerror& Error) {
COLcerr << Error.description() << newline;
return EXIT_FAILURE;
} catch(...) {
COLcerr << "Unhandled Exception" << newline;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
Then to solve the linking issue in the video, I needed to add the CMD dir to the DIRS list:
TARGET=HelloWorld
DIRS=\
CMD\
COL
include ../make/makefile.core
See the extra line on line 4? This includes the CMD library. Libraries did need to occur in order with the lowest level dependencies shown last. Not sure if that applies anymore. COL is the core library of everything, CMD uses it and so CMD needs to appear before COL in the DIRS variable. The \ at the end of the CMD line is just make’s continuation character.
I put in tracing after Parser.parseArgs:
Parser.parseArgs(argc, argv);
COL_TRC("Parsed " << argc << " arguments");
COL_DBG("This is really detailed tracing.");
COL_VAR(argc);
And I needed to add this to the includes:
Next to add the code to parse command line arguments, there were two blocks of code I had to add:
And:
And we are done.