Solved

C++ help compiling CmdLine

Posted on 2009-05-04
10
576 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
Comment Utility
Are you #include-ing the deprecated <iostream.h>, rather than <iostream> ?
0
 

Author Comment

by:wevouch
Comment Utility
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
Comment Utility
And in cmdline.h, these two lines :

>> class  ostream ;
>> class  istream ;

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

        #include <iosfwd>
0
 
LVL 53

Assisted Solution

by:Infinity08
Infinity08 earned 450 total points
Comment Utility
>> 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
Comment Utility
Or maybe, using a different option parser, like getopt is an option ?

        http://www.gnu.org/software/hello/manual/libc/Getopt.html
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:wevouch
Comment Utility
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
Comment Utility
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
Comment Utility
>>>> 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
Comment Utility
>> 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
Comment Utility
>>>> 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

771 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now