Taner Şenyurt

Kişisel gelişim sitesi…

Gcc 4.3 and Header issues


I’m using gcc 4.3.3 version and nowadays i’m trying to write hybrid file transfer system with c++ on Linux.The problem is i used to use some function in c or c++ like strcmp() with including string library but now when i try to compile I’m getting some error like
error: ‘strcmp’ was not declared in this scope
Simple example code
In gcc 4.1 version i can compile this code without any error or warning

  1. #include <string>
  2. #include <iostream>
  3. using namespace std;
  4. main()
  5. {
  6.         if(!strcmp("gccHeaderIssue","gccHeaderIssue"))
  7.         {
  8.         cout<<"kelimeler ayni"<<endl;
  9.         }
  10. }

but same code can’t compile in gcc 4.3 ,it returns error like

  1. x.cpp: In function ‘int main()’:
  2. x.cpp:7: error: ‘strcmp’ was not declared in this scope

We can solve this error with including cstring library .After that our code is

  1. #include <string>
  2. #include <iostream>
  3. #include <cstring>
  4. using namespace std;
  5. main()
  6. {
  7.         if(!strcmp("gccHeaderIssue","gccHeaderIssue"))
  8.         {
  9.         cout<<"kelimeler ayni"<<endl;
  10.         }
  11. }

The other missing headers

If missing Then include this header
find, for_each, sort <algorithm>
ostream_iterator, istream_iterator <iterator>
auto_ptr <memory>
typeid <typeinfo>
isalnum, toupper <cctype>
printf <cstdio>
atoi, free, rand, exit <cstdlib>
EXIT_FAILURE <cstdlib>
strcmp, strdup, strcpy, memcpy <cstring>

Removal of Pre-ISO headers

Various backwards and deprecated headers have been removed.

If missing Then include this header
<algobase.h> <algorithm>
<algo.h> <algorithm>
<alloc.h> <memory>
<bvector.h> <vector>
<complex.h> <complex>
<defalloc.h> <memory>
<deque.h> <deque>
<fstream.h> <fstream>
<function.h> <functional>
<hash_map.h> <tr1/unordered_map>
<hashtable.h> <tr1/unordered_map> or <tr1/unordered_set>
<heap.h> <queue>
<iomanip.h> <iomanip>
<iostream.h> <iostream>
<istream.h> <istream>
<iterator.h> <iterator>
<list.h> <list>
<map.h> <map>
<multimap.h> <map>
<multiset.h> <set>
<new.h> <new>
<ostream.h> <ostream>
<pair.h> <utility>
<queue.h> <queue>
<rope.h> <ext/rope>
<set.h> <set>
<slist.h> <ext/slist>
<stack.h> <stack>
<streambuf.h> <streambuf>
<stream.h> <iostream>
<tempbuf.h> <ext/memory>
<tree.h> <ext/rb_tree> or <ext/pb_ds/assoc_container.hpp>
<vector.h> <vector>

More information and solution for porting old programs to gcc 4.3 : http://gcc.gnu.org/gcc-4.3/porting_to.html

One Comment to

“Gcc 4.3 and Header issues”

  1. On July 22nd, 2009 at 8:23 pm Miguel Says:

    Thanks for this post
    Could you help me?
    I change to but when I execute the makefile, the program give me the next error:

    MOFSVar.h:73: error: expected `)’ before ‘&’ token
    MOFSVar.h:90: error: ‘ofstream’ not was declared

    L_73: MOFSVar(ifstream& file_in);
    L_90: void SalvarIncidencia(ofstream& file_out);

    and congratullations for the aspect of website