|
Boost Users : |
From: ope (ope-devel_at_[hidden])
Date: 2008-01-22 13:53:14
Hi,
to get the main() more clean, I moved the command line options parser to
an own class (some stuff missing):
---8---
class CommandLineOptions
{
public:
CommandLineOptions( int argc, char** argv );
private:
po::options_description generic_options;
po::options_description qt4_common;
#if defined( Q_OS_UNIX ) || defined( Q_OS_MAC )
po::options_description qt4_x11;
#endif
#if defined( Q_OS_WIN )
po::options_description qt4_win;
#endif
#if defined DEBUG
po::options_description qt4_dbg;
#endif
po::options_description hidden_options;
po::options_description usage_options;
po::options_description cmdline_options;
po::positional_options_description pos_options;
po::variables_map vm;
};
--->8---
with
---8<---
CommandLineOptions::CommandLineOptions( int argc, char** argv )
: generic_options("Generic options"),
qt4_common("Qt options"),
#if defined( Q_OS_UNIX ) || defined( Q_OS_MAC )
qt4_x11( "Qt X11 specific options" ),
#endif
#if defined( Q_OS_WIN )
qt4_win( "Qt Windows specific options" ),
#endif
#if defined( DEBUG )
qt4_dbg( "Qt debug options" ),
#endif
hidden_options("Hidden options")
{
generic_options.add_options()
( "version,v", "print version string")
( "help,h", "produce help message")
;
hidden_options.add_options()(...);
qt4_common.add_options()(...
#if defined( Q_OS_UNIX ) || defined( Q_OS_MAC )
qt4_x11.add_options()(...
#if defined( Q_OS_WIN )
qt4_win.add_options()(...
#if defined( DEBUG )(...
usage_options
.add( generic_options )
.add( qt4_common )
#if defined( Q_OS_UNIX ) || defined( Q_OS_MAC )
.add( qt4_x11 )
#elif defined( Q_OS_WIN )
.add( qt4_win )
#endif
#if defined( DEBUG )
.add( qt4_dbg )
#endif
;
cmdline_options.add( usage_options ).add( hidden_options );
pos_options.add( "input-file", -1 );
po::store(po::command_line_parser(argc, argv).
options(cmdline_options).positional(pos_options).run(), vm);
po::notify(vm);
if (vm.count( "version" )) {
std::cout << Version() << "\n";
}
...
}
--->8---
and the main():
---8<---
int main( int argc, char **argv )
{
try {
logging::init();
CommandLineOptions cmdline( argc, argv );
QT_REQUIRE_VERSION( argc, argv, QT_VERSION_STR );
Q_INIT_RESOURCE( workbench );
QApplication app( argc, argv );
QMainWindow wb;
wb.show();
// using boost.logging v2
L_ << "execute application.";
return app.exec();
...
--->8---
It works fine until the app exits. My gdb session wasn't very useful to me:
(gdb) target exec ./edas
(gdb) run
Starting program: /.../edas2/edas
Using host libthread_db library "/lib/i686/cmov/libthread_db.so.1".
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
(no debugging symbols found)
[Thread debugging using libthread_db enabled]
[New Thread 0xb70506c0 (LWP 13445)]
[New Thread 0xb6aa5b90 (LWP 13450)]
28:31 [1] execute application.
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb70506c0 (LWP 13445)]
0x08051980 in ?? ()
(gdb) backtrace
#0 0x08051980 in ?? ()
If I comment out my CommandLineOptions class instance it works.
Thanks,
Olaf
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net