Which lib to include in my build to use 'isascii' (ctype.h)?

Started by
4 comments, last by andrew111 11 years, 11 months ago
Hi,
I'm trying to compile (with mingw) some code using a library (clang), which in turn requires the use of 'isascii'.


But on making it I get the error message:

'isascii' was not declared in this scope


Which I've been solving a lot of similar errors of functions not being found by figuring out the lib name required to be included (e.g: in the compile call: g++ myprog.cpp -o myprog.exe -lsomelib -lsomeotherlib).

But in this case I'm at a loss at what is required. Various documentation pages on isascii mention it is included with 'ctype.h' but mentions nothing on what library is required for it.

So anyone know if there is a commandline or a library that I need to include with my g++ call, thanks.
Advertisement
That's a compiler error, which means you need to change the source code. A linker error would be different, and would be solvable by adding a library.

ctype.h should be part of the standard library distributed with the compiler, and it should know enough to link in the appropriate libs for it if you have the code compiling cleanly.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

[font=courier new,courier,monospace]isascii()[/font] is a POSIX (X/Open) function originating in both BSD and System V Unix. It is not a standard C function.

My guess is that in order to get the symbol into visible scope in a mingw environment when using either the GCC or Clang compilers, you will need to #define either [font=courier new,courier,monospace]_BSD_SOURCE[/font], [font=courier new,courier,monospace]_SVID_SOURCE[/font], or [font=courier new,courier,monospace]_XOPEN_SOURCE[/font] before #including [font=courier new,courier,monospace]<ctype.h>[/font] in your source. This is just a guess, reading [font=courier new,courier,monospace]<ctype.h>[/font] will probably reveal the ultimate truth.

It may be the case that the C runtime library does not provide any implementation of [font=courier new,courier,monospace]isascii() [/font]in the mingw environment (which should be using the Microsoft C runtime), in which case you're just simply out of luck. Try to use one of the standard character classification functions instead, you may just find they do a better job at whatever you're trying to do.

Stephen M. Webb
Professional Free Software Developer


That's a compiler error, which means you need to change the source code. A linker error would be different, and would be solvable by adding a library.

What confuses me is that the error points to a body of a function which is calling isascii, from within a header of the clang library, which compiled successfully (thereby not running into the same problem). Does that mean when a header file has functions with a body (as opposed to bodyless decl like "void func();") that it will be compiled into the program including the header, rather than just linking to it in whatever library the header comes from?


ctype.h should be part of the standard library distributed with the compiler, and it should know enough to link in the appropriate libs for it if you have the code compiling cleanly.

Thanks, that got me thinking about my compile options and I removed '-std=c++0x', which fixed that.

Does that mean when a header file has functions with a body (as opposed to bodyless decl like "void func();") that it will be compiled into the program including the header, rather than just linking to it in whatever library the header comes from?


Yep. #include is a literal text-replace and anything the compiler sees will be compiled. The compiler has no idea what library "a header comes from". In fact, the compiler doesn't even know what a header is - the preprocessor takes care of that and is a very simple beast. The compiler just sees a translation unit - one text file.
I see, that makes sense, thanks.

This topic is closed to new replies.

Advertisement