Error including ctype.h source

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Error including ctype.h source

3,071 Views
Veter
Contributor I
I have included #include <ctype.h> into my souce.
It gives me error: Link Error   : Undefined : "__ctype_mapC" Referenced from "isprint" in *.cpp
 
The reference looks like this:
if ( isprint( dataBuffer[i] ) )
{
 //do your thing
}
 
Why I can't include regular header files?
Is there anything special I need to do in order to include c header files?
Labels (1)
0 Kudos
3 Replies

580 Views
mccPaul
Contributor I
Hi Veter,
 
You can't include C headers in C++ files unless you tell the compiler that the included code is C and not C++. This is because the C and C++ functions are called in different ways.
 
You tell the compiler that the files are C by using this construct:
 
Code:
extern "C"{// C function declarations as normal...}

 
If you are including your own headers, it is a good idea to use #defines like so:
 
Code:
// At the start of the header file put this:#ifdef __cplusplusextern "C" {#endif // At the end of the header put this:#ifdef __cplusplus}#endif

 
If you are using system headers that you cannot modify do this where you include them:
 
Code:
extern "C"{#include "ctype.h"}

 
Cheers,
 
Paul.
0 Kudos

580 Views
Veter
Contributor I
Hi Paul,
 
I tried the same thing with <time.h>, but I still get error. It seems that "time_t" structure is not recognized in CodeWarrior for ColdFire version 6.3.
 
My include statement is following:
#ifdef __cplusplus
extern "C" {
#endif
#include <time.h>
#ifdef __cplusplus
}
#endif
 
Any idea how can I include support for time_t and time support bypassing MSL?
0 Kudos

580 Views
mccPaul
Contributor I
Hi,
 
It depends on the libraries you are using (I don't use CodeWarrior), but I suspect that the time_t type is typedef'd in sys/types.h, so you would need to do this:
 
#ifdef __cplusplus
extern "C" {
#endif
#include <sys/types.h>
#include <time.h>
#ifdef __cplusplus
}
#endif
 
What is the linker error that you are getting, if that doesn't work?
 
Paul.

Message Edited by mccp on 2007-04-2305:25 PM

0 Kudos