views:

398

answers:

6

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
A: 

If wxWidgets is C++, and it includes and and your compiler prevents inclusion of and when cstring/cstdio are included, then strlen would be in the std namespace instead of global. Try std::strlen and see if that fixes the error.

Mark B
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>"
sciloop
#include of system headers (<>) should almost always come before #include of local headers ("")
Ben Voigt
Putting the system headers in front did not change the error messages.
sciloop
A: 

Try #include<cstdio> and #include<cstring>, which are the headers for C++

gc
Also this does not work. The same messages appear...too bad.
sciloop
+1  A: 

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.

Michael Burr
1.#ifdef __cplusplusinline 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
Michael, thanks very much for the great help. With the MSVC directory in the first place it works now!
sciloop
A: 

The comment field is too small. I answer to Michael Burr:

A.

#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; }`

B. 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>

C. Here`s the some lines before and a line after the first error message:

1>Note: including file: M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/chartype.h
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\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\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:  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>M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/wxcrtbase.h(696) : error C3861: 'strlen': identifier not found
1>M:\Visual Studio 2008\Projects\general\wxWidgets-2.9.0\include\wx/wxcrtbase.h(709) : error C3861: '_strdup': identifier not found
sciloop
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.
Michael Burr
ok, I`ll do so.
sciloop
@sciloop: I've modified my answer based on the infomration you added to your question.
Michael Burr
A: 

Try:

#include <cstdio>
#include <cstring>
#include <cctype>
#include <cwctype>
#include <ctime>
#include <cio>

using namespace std;

#include "wxcrtbase.h"
#include "wx/chartype.h"

int main(void) {
    return strlen("hey there good buddy!");
}

This is the stuff that I hate about c++ the most.

nategoose
Are you sure "<cio>" exists? I get errors and I cannot find it on the internet( google )?
sciloop
When I compile YOUR code with cio replaced with io.h, I get the same error messages again
sciloop
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?!
sciloop
All I was trying to demonstrate was a different ordering of the includes and namespace usage. <cio> should mean "namespace std { #include <io.h> }".
nategoose
A: 

I indeed think that you have to include cstdio and cstring (as proposed above), but in this case everything will reside in namespace std, like std::strlen and such...

Randall Flagg