fatal error: strtok_r.h: No such file or directory

2020-07-27 15:34发布

I'm compiling tesseract-ocr-3.01 in MinGW, and I'm getting this error ambigs.cpp:31:22: fatal error: strtok_r.h: No such file or directory

This is the code where the error is:

#ifdef WIN32
#ifndef __GNUC__
#define strtok_r strtok_s
#else
#include "strtok_r.h"
#endif  /* __GNUC__ */
#endif  /* WIN32 */

Edit

I found this feature request to add strtok_r.h to MinGW. From the comments there:

strtok_r() is an optional POSIX function, required only for implementations which support POSIX threads. MinGW does not support POSIX threads; therefore, I don't think that this function has any place in a base MinGW distribution.

POSIX threads support for MS-Windows is provided by the pthreads-win32 project. Maybe they already provide a strtok_r() implementation. If so, then you could use it; if not, you might ask them to consider adding it.

1条回答
不美不萌又怎样
2楼-- · 2020-07-27 16:29

The problem is most easily solved by adding an strtok_r implementation to the project's sources:

char *strtok_r(char *str, const char *delim, char **save)
{
    char *res, *last;

    if( !save )
        return strtok(str, delim);
    if( !str && !(str = *save) )
        return NULL;
    last = str + strlen(str);
    if( (*save = res = strtok(str, delim)) )
    {
        *save += strlen(res);
        if( *save < last )
            (*save)++;
        else
            *save = NULL;
    }
    return res;
}
查看更多
登录 后发表回答