致命错误:strtok_r。h:没有这样的文件或目录(在MinGW编译tesserac -ocr-3.01时)

时间:2021-08-10 08:58:36

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

我在MinGW中编译tesserac -ocr-3.01,我得到了这个错误的ambigs。cpp:31:22:致命错误:strtok_r。h:没有这样的文件或目录

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。MinGW h。的评论:

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.

strtok_r()是一个可选的POSIX函数,只用于支持POSIX线程的实现。MinGW不支持POSIX线程;因此,我不认为这个函数在基明w分布中有任何位置。

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.

支持MS-Windows的POSIX线程由pthreads-win32项目提供。也许他们已经提供了一个strtok_r()实现。如果是,那么你可以用它;如果没有,你可以让他们考虑添加它。

1 个解决方案

#1


1  

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

通过将strtok_r实现添加到项目的源代码中,最容易解决这个问题:

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

#1


1  

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

通过将strtok_r实现添加到项目的源代码中,最容易解决这个问题:

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