• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 606
  • Last Modified:

C++ help compiling CmdLine

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
wevouch
Asked:
wevouch
  • 6
  • 2
  • 2
4 Solutions
 
Infinity08Commented:
Are you #include-ing the deprecated <iostream.h>, rather than <iostream> ?
0
 
wevouchAuthor Commented:
Yes, I think the CmdLine code base is using iostream.h
But that usually only results in a warning right?
0
 
Infinity08Commented:
And in cmdline.h, these two lines :

>> class  ostream ;
>> class  istream ;

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

        #include <iosfwd>
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Infinity08Commented:
>> 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
 
Infinity08Commented:
Or maybe, using a different option parser, like getopt is an option ?

        http://www.gnu.org/software/hello/manual/libc/Getopt.html
0
 
wevouchAuthor Commented:
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
 
Infinity08Commented:
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
 
itsmeandnobodyelseCommented:
>>>> 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
 
Infinity08Commented:
>> 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
 
itsmeandnobodyelseCommented:
>>>> 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: 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.

  • 6
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now