Header correct, but identifier not found

23,929

A few things to try and/or answer:

  • Can you post at least the few lines around and including the one that the compiler generates the 'identifier not found' error?
  • When you say you have an #include <string.h> line, exactly which file(s) and does it precede the various wx includes?
  • Can you post the output of the included headers when you build with the /showIncludes option (it's in the VS 2008 IDE's C++ project property page under "C/C++/Advanced/Show Includes")?

Edit, with new information:

Based on the edit you made that included a more complete listing from /showIncludes, it appears that you might have the INCLUDE path set incorrectly. Here are a couple of lines from the log:

1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\cstring
1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx\string.h

When MSVC's cstring header is trying to include string.h, it's picking up a string.h header from the wx library instead of the one that's part of the compiler distribution (which would be in C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\string.h).

I'm not sure why the wx library would name one of their own headers string.h (instead of, say, wxString.h), but I assume that it's intended to be picked up by someone using something like:

#include "wx/string.h"

Regardless, I think you'll fix your problem by making sure that the MSVC include directory is in the INCLUDE search path before any other directory.

Share:
23,929
sciloop
Author by

sciloop

Updated on May 20, 2020

Comments

  • sciloop
    sciloop almost 4 years

    I have two projects (x64).

    A. Written in C (wxWidgets) --- edit: its in C++!

    B. Written in C++

    A compiles fine, but B (which uses functions of A) gives several errors when I try to compile.

    I suggest that the reason for the errors is the same for all, so I mention only the first. It says:

    strlen: identifier not found
    

    In the file which gives the error messages ( wxcrtbase.h ), the following headers are included:

    #include <stdio.h>
    #include <string.h>`
    

    The files from B include the following headers from A:

    #include "wx/wx.h"
    #include "wx/dcbuffer.h" 
    #include "wx/spinctrl.h"
    

    So, currently, I have no idea where to start to search for the reason of the errors. May it be that I have C and C++ files? Maybe that I compiled for x64?

    Thanks for help!

    edit: more info
    the lines in wxcrtbase.h around the one producing the first error message are:

    #ifdef __cplusplus  
    inline size_t wxStrlen(const char *s) { return s ? wxCRT_StrlenA(s) : 0; }  
    inline size_t wxStrlen(const wchar_t *s) { return s ? wcslen(s) : 0; }  
    

    The order of the includes of the wxcrtbase.h is

    #include <stdio.h>
    #include <string.h>
    #include <ctype.h>
    #include <wctype.h>
    #include <time.h>
    #include <io.h>
    

    The /showIncludes lists the following ( I stop with the list after the first two error messages ):

    1>Compiling...
    1>widget.cpp
    1>Note: including file: m:\visual studio 2008\projects\general\rama\src\widget.h
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include \string
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\istream
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\ostream
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\ios
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xlocnum
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\climits
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\yvals.h
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\sal.h
    1>Note: including file: c:\program files (x86)\microsoft visual studio 9.0\vc\include\codeanalysis\sourceannotations.h
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\crtassem.h
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\vadefs.h
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\use_ansi.h
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\limits.h
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\cstdio
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\stdio.h
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\swprintf.inl
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\cstdlib
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\stdlib.h
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\streambuf
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xiosbase
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\xlocale
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\cstring
    1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx\string.h
    1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/defs.h
    1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/platform.h
    1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\setupp.h
    1>Note: including file: m:\visual studio 2008\projects\general\wxwidgets-2.9.0\include\wx/version.h
    1>Note: including file: m:\visual studio 2008\projects\general\wxwidgets-2.9.0\include\wx/cpp.h
    1>Note: including file: m:\visual studio 2008\projects\general\wxwidgets-2.9.0\include\wx/cpp.h
    1>Note: including file: M:/Visual Studio 2008/Projects/general/wxWidgets-2.9.0/lib/vc_lib/mswud/wx/setup.h
    1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/msw/libraries.h
    1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/chkconf.h
    1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/msw/chkconf.h
    1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/version.h
    1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/dlimpexp.h
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\stddef.h
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
    1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/debug.h
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\assert.h
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
    1>Note: including file:  M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/chartype.h
    1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/platform.h
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\tchar.h
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\wchar.h
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\wtime.inl
    1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/cpp.h
    1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/windowid.h
    1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/msw/winundef.h
    1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/features.h
    1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx\string.h
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\stdarg.h
    1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/wxcrtbase.h
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\io.h
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
    1>Note: including file:  C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\cctype
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\ctype.h
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\cwctype
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\wctype.h
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\ctime
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\time.h
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\crtdefs.h
    1>Note: including file: C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\include\time.inl
    1>Note: including file:  M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/chartype.h
    1>M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/wxcrtbase.h(705) : error C3861: 'strlen': identifier not found
    1>M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/wxcrtbase.h(718) : error C3861: '_strdup': identifier not found
    
  • sciloop
    sciloop about 14 years
    Unfortunately, that does not work. Message: std is not a class or namespace. The headers of the wxcrtbase.h file are: "#include "wx/chartype.h" #include <stdio.h> #include <string.h> #include <ctype.h> #include <wctype.h> #include <time.h> #include <io.h>"
  • Ben Voigt
    Ben Voigt about 14 years
    #include of system headers (<>) should almost always come before #include of local headers ("")
  • sciloop
    sciloop about 14 years
    1. #ifdef __cplusplus inline size_t wxStrlen(const char *s) { return s ? wxCRT_StrlenA(s) : 0; } inline size_t wxStrlen(const wchar_t *s) { return s ? wcslen(s) : 0; } 2. the string.h is only in the wxWidgets files. There the original order is: #include <stdio.h> #include <string.h> #include <ctype.h> #include <wctype.h> #include <time.h> #include <io.h> 3. I did what you suggested. The output is very long. I have to do a new post for that.
  • sciloop
    sciloop about 14 years
    Putting the system headers in front did not change the error messages.
  • sciloop
    sciloop about 14 years
    Are you sure "<cio>" exists? I get errors and I cannot find it on the internet( google )?
  • Michael Burr
    Michael Burr about 14 years
    I think you should edit your question to include this information instead of having it in a answer to make it easier on people who might want to help answer the question. Also, I think you may need to include all the lines from the /showIncludes output for one .c/.cpp file - at least up to the error C3861 lines. What you've shown doesn't indicate that string.h was included, but that's probably because it was before wherever you decided to start the copy/paste.
  • sciloop
    sciloop about 14 years
    When I compile YOUR code with cio replaced with io.h, I get the same error messages again
  • sciloop
    sciloop about 14 years
    But, at least its good to see that the problem exists even without my own project B. So, it must be a problem inside wxWidgets?!
  • Michael Burr
    Michael Burr about 14 years
    I've modified my answer based on the infomration you added to your question.
  • nategoose
    nategoose about 14 years
    All I was trying to demonstrate was a different ordering of the includes and namespace usage. <cio> should mean "namespace std { #include <io.h> }".
  • sciloop
    sciloop about 14 years
    Michael, thanks very much for the great help. With the MSVC directory in the first place it works now!
  • Shahbaz
    Shahbaz over 12 years
    I am so tempted to downvote you! How can replacing string.h with cstring solve the problem??!
  • Shahbaz
    Shahbaz over 12 years
    replacing stdio.h and string.h by cstdio and cstring doesn't solve anything.