Problems with g++-4.3; strchr was not declared in this scope

Asked by jim

The following is the part of the code, along with the include statements where the problem occurs.
The following is a snip from the code: convertIt.cxx
...
#define __NO_USE_STD_IOSTREAM
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cstdio>

using namespace std;
...
istream& operator>>(istream& i, real& r)
{
  static char buf[132];
  i >> buf;
  char* D = (strchr(buf,'D')); if(D) *D='E';
  char* d = (strchr(buf,'d')); if(d) *d='E';
  sscanf(buf,"%lf",&r.r);
  return i;
}
...
root@ubuntu:/usr/eiger/src# g++ -c convertIt.cxx
convertIt.cxx: In function ‘std::istream& operator>>(std::istream&, real&)’:
convertIt.cxx:160: error: ‘strchr’ was not declared in this scope
...
...
Also:: ' error: 'strcmp' was not declared in this scope (later in the code).

root@ubuntu:/usr/eiger/src# ls -l /usr/bin/g++
lrwxrwxrwx 1 root root 7 2009-03-06 13:03 /usr/bin/g++ -> g++-4.3

NOTE: In an older version of Ubuntu, with g++-4.1 the module compiled without errors.

Any ideas.

Thanks,
Jim

Question information

Language:
English Edit question
Status:
Solved
For:
Ubuntu gcc-defaults Edit question
Assignee:
No assignee Edit question
Solved by:
Antonio Litterio
Solved:
Last query:
Last reply:
Revision history for this message
Best Antonio Litterio (antonio-litterio-gmail) said :
#1

Hi, the function strcmp is defined in "cstring" or "string.h" and isn't in "string" library. Adding this include...

Revision history for this message
jim (send2jop) said :
#2

Thank you very much.
That is correct, it does solve the problem.
The question that still bothers me is why it woked under g++-4.1,
but not under g++4.3, which is a newer version.
Anyway, thank you for your help.
Jim

Revision history for this message
Antonio Litterio (antonio-litterio-gmail) said :
#3

The answer is this:
In GCC 3.4 for compile faster, the C++ header dependency have been cleaned up. The downside is that you need to directly include everything you use.

Read this for more info:
http://www.cyrius.com/journal/2007/05/10#gcc-4.3-include

Antonio