Solved

C++ help compiling CmdLine

Posted on 2009-05-04
10
581 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

805 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