Solved

C++ help compiling CmdLine

Posted on 2009-05-04
10
582 Views
Last Modified: 2013-11-17
Hi All, I need help compiling and building CmdLine (http://www.cmcrossroads.com/bradapp/ftp/src/libs/C++/CmdLine.html) on my Redhat linux server here. I tried but ran into the following error...

$ make library
for i in src ; do \
                ( cd $i ; make - "FLAG=-O" "TESTDEFS=" "USRDEFS=-DDEBUG_CMDLINE" "OPTIONS=" library ) ; \
        done
make[1]: Entering directory `/home/nmittal/RSIGrid/Libraries/CmdLine/CmdLine/src'
for i in lib ; do \
                ( cd $i ; make -w -- OPTIONS= USRDEFS=-DDEBUG_CMDLINE TESTDEFS= FLAG=-O "FLAG=-O" "TESTDEFS=" "USRDEFS=-DDEBUG_CMDLINE" "OPTIONS=" library ) ; \
        done
make[2]: Entering directory `/home/nmittal/RSIGrid/Libraries/CmdLine/CmdLine/src/lib'
make[2]: Warning: File `cmdline.h' has modification time 81 s in the future
g++ -O -I./  -DDEBUG_CMDLINE  -Dunix_style  -c argiter.c
In file included from /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/backward/iostream.h:31,
                 from argiter.c:13:
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
cmdline.h:24: error: using typedef-name â¬Üstd::ostreamâ¬" after â¬Üclassâ¬"
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/iosfwd:138: error: â¬Üstd::ostreamâ¬" has a previous declaration here
cmdline.h:25: error: using typedef-name â¬Üstd::istreamâ¬" after â¬Üclassâ¬"
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/iosfwd:137: error: â¬Üstd::istreamâ¬" has a previous declaration here
make[2]: *** [argiter.o] Error 1
make[2]: Leaving directory `/home/nmittal/RSIGrid/Libraries/CmdLine/CmdLine/src/lib'
make[1]: *** [library] Error 2
make[1]: Leaving directory `/home/nmittal/RSIGrid/Libraries/CmdLine/CmdLine/src'
make: *** [library] Error 2
[CmdLine]

thanks for your help in advance.

Nishant

0
Comment
Question by:wevouch
  • 6
  • 2
  • 2
10 Comments
 
LVL 53

Expert Comment

by:Infinity08
ID: 24294377
Are you #include-ing the deprecated <iostream.h>, rather than <iostream> ?
0
 

Author Comment

by:wevouch
ID: 24294391
Yes, I think the CmdLine code base is using iostream.h
But that usually only results in a warning right?
0
 
LVL 53

Assisted Solution

by:Infinity08
Infinity08 earned 450 total points
ID: 24294411
And in cmdline.h, these two lines :

>> class  ostream ;
>> class  istream ;

should not be there. instead, you can add this #include :

        #include <iosfwd>
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 53

Assisted Solution

by:Infinity08
Infinity08 earned 450 total points
ID: 24294437
>> Yes, I think the CmdLine code base is using iostream.h
>> But that usually only results in a warning right?

It is just a warning, yes (which can be disabled using -Wno-deprecated if you want to).
But it is an indication that the code is ancient (ie. written before the C++ standard), and should possibly be ported.

You can try getting it to run like this, but the two errors re. the ostream and istream forward declarations can't be resolved without modifying the code.

So, either you use the proper <iostream> header, and modify the code accordingly (and make the modification from my previous post).
Or, you fix the errros by looking up the proper forward declarations for the ostream and istream types (look in the iostream.h header file for your compiler).
0
 
LVL 53

Accepted Solution

by:
Infinity08 earned 450 total points
ID: 24294479
Or maybe, using a different option parser, like getopt is an option ?

        http://www.gnu.org/software/hello/manual/libc/Getopt.html
0
 

Author Comment

by:wevouch
ID: 24294646
I like the interface for CmdLine, so I want to give it a shot before I try getopt.
I changed all occurances of #include <iostream.h> to $include <iostream>.
Now I get...

$ sudo make all
for i in src doc ; do \
                ( cd $i ; make - "FLAG=-O" "TESTDEFS=" "USRDEFS=-DDEBUG_CMDLINE" "OPTIONS=" all ) ; \
        done
make[1]: Entering directory `/home/nmittal/RSIGrid/Libraries/CmdLine/CmdLine/src'
for i in lib cmd  ; do \
                ( cd $i ; make -w -- OPTIONS= USRDEFS=-DDEBUG_CMDLINE TESTDEFS= FLAG=-O "FLAG=-O" "TESTDEFS=" "USRDEFS=-DDEBUG_CMDLINE" "OPTIONS=" all ) ; \
        done
make[2]: Entering directory `/home/nmittal/RSIGrid/Libraries/CmdLine/CmdLine/src/lib'
g++ -O -I./  -DDEBUG_CMDLINE  -Dunix_style  -c argiter.c
argiter.c: In member function â¬Üvirtual const char* CmdIstreamIter::operator()()â¬":
argiter.c:130: error: no match for â¬Üoperator!â¬" in â¬Ü!((CmdIstreamIter*)this)->CmdIstreamIter::isâ¬"
argiter.c:130: note: candidates are: operator!(bool) <built-in>
argiter.c:135: error: invalid use of undefined type â¬Üstruct istreamâ¬"
cmdline.h:25: error: forward declaration of â¬Üstruct istreamâ¬"
argiter.c:146: error: could not convert â¬Ü((CmdIstreamIter*)this)->CmdIstreamIter::isâ¬" to â¬Üboolâ¬"
make[2]: *** [argiter.o] Error 1
make[2]: Leaving directory `/home/nmittal/RSIGrid/Libraries/CmdLine/CmdLine/src/lib'
make[2]: Entering directory `/home/nmittal/RSIGrid/Libraries/CmdLine/CmdLine/src/cmd'
( cd ../lib/ ; make -w -- FLAG=-O TESTDEFS= USRDEFS=-DDEBUG_CMDLINE OPTIONS= "FLAG=-O" "TESTDEFS=" "USRDEFS=-DDEBUG_CMDLINE" "OPTIONS=" library ; )
make[3]: Entering directory `/home/nmittal/RSIGrid/Libraries/CmdLine/CmdLine/src/lib'
g++ -O -I./  -DDEBUG_CMDLINE  -Dunix_style  -c argiter.c
argiter.c: In member function â¬Üvirtual const char* CmdIstreamIter::operator()()â¬":
argiter.c:130: error: no match for â¬Üoperator!â¬" in â¬Ü!((CmdIstreamIter*)this)->CmdIstreamIter::isâ¬"
argiter.c:130: note: candidates are: operator!(bool) <built-in>
argiter.c:135: error: invalid use of undefined type â¬Üstruct istreamâ¬"
cmdline.h:25: error: forward declaration of â¬Üstruct istreamâ¬"
argiter.c:146: error: could not convert â¬Ü((CmdIstreamIter*)this)->CmdIstreamIter::isâ¬" to â¬Üboolâ¬"
make[3]: *** [argiter.o] Error 1
make[3]: Leaving directory `/home/nmittal/RSIGrid/Libraries/CmdLine/CmdLine/src/lib'
make[2]: *** [library] Error 2
make[2]: Leaving directory `/home/nmittal/RSIGrid/Libraries/CmdLine/CmdLine/src/cmd'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/home/nmittal/RSIGrid/Libraries/CmdLine/CmdLine/src'
make[1]: Entering directory `/home/nmittal/RSIGrid/Libraries/CmdLine/CmdLine/doc'
make[1]: Nothing to be done for `all'.
make[1]: Leaving directory `/home/nmittal/RSIGrid/Libraries/CmdLine/CmdLine/doc'
$
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24295270
All stream types (like istream, ostream, etc.) have to be prefixed with std:: now (like std::istream, std::ostream, etc.), as they are in the std namespace.
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 24297503
>>>> argiter.c:135: error: invalid use of undefined type â¬Üstruct istreamâ¬"
You probably should rename the argiter.c to argiter.cpp if using iostream classes.
It is not the g++ wouldn't  be able to use the C++ compiler rather the ANSI C compiler on a .c file but you should use the proper file extension if you don't want to confuse others.

Then below

#include <iostream>

you may define

using namespace std;

to not having to use the std:: prefix.
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 24297531
>> using namespace std;

Dumping a whole namespace into the global namespace is not recommended at all. So, I wouldn't do that, not even for the sake of saving a few keystrokes.
0
 
LVL 39

Assisted Solution

by:itsmeandnobodyelse
itsmeandnobodyelse earned 50 total points
ID: 24298021
>>>> So, I wouldn't do that, not even for the sake of saving a few keystrokes.
It is common practice to do so in the cpp files.

For a .c source ported to .cpp namespace issues must not be expected. On the contrary, if for example a variable named 'string' was used and now doesn't compile, these things should be changed anyhow.

It is not the few keystrokes but the (unnecessary) amount of changes which makes it difficult to find out the real portation issues. I can say that cause I helped to port a 10-million lines of code project from VC6 and RogueWave to VC8 and STL. One of our guidelines was to change as little as possible of the running code in order to be able to use the stored code history of our configuration management system for these major changes nevertheless.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question