strncasecmp 和 strcasecmp 尚未声明

Let*_*ren 5 c++ string-comparison assimp

我尝试在 Code::Blocks 中使用 MinGW 编译 Assimp,但出现以下错误。

\assimp-3.3.1\assimp-3.3.1\code\StringComparison.h||In function 'int Assimp::ASSIMP_stricmp(const char*, const char*)':|
\assimp-3.3.1\assimp-3.3.1\code\StringComparison.h|144|error: '::strcasecmp' has not been declared|
\assimp-3.3.1\assimp-3.3.1\code\StringComparison.h||In function 'int Assimp::ASSIMP_strincmp(const char*, const char*, unsigned int)':|
\assimp-3.3.1\assimp-3.3.1\code\StringComparison.h|193|error: '::strncasecmp' has not been declared|
Run Code Online (Sandbox Code Playgroud)

在搜索时,我发现有问题的两个函数(strcasecmp 和 strncasecmp)实际上是在其中声明的,string.h该函数包含在StringComparison.h. 我还设法获取了strings.h它们最初所属的文件,但包括该文件也没有解决问题。

在搜索这个网站时,我发现我并不是唯一一个遇到这个问题的人。我发现的另一个解决方案建议使用定义语句,因为这些函数的名称可能略有不同,但这也没有帮助。

sam*_*gak 3

我刚刚遇到了这个完全相同的问题,这个问题是在谷歌搜索解决方案时出现的,所以我将在这里记录我的狡猾的解决方案:

最后,我通过对 Assimp 源代码进行多次小修改就成功了。解决字符串问题不足以使其正常工作,因为它在构建的后期会失败。我将在下面列出我所做的编辑。我建议一次制作一个,然后重建,以防万一您的设置出于某种原因不需要其中一些。请注意,由于最后一次编辑(对 Exporter.cpp),您无法使用此解决方案进行模型导出,如果您确实需要,则必须找出另一种方法来修复链接错误。

这不是一个干净的解决方案,它可能会被 Assimp 的未来版本取代,届时我将删除它。这是针对 assimp-3.3.1,使用 MinGW 构建的:

在 StringComparison.h 中,编辑该ASSIMP_stricmp函数,注释掉除else#ifdef 子句之外的所有内容:

/*#if (defined _MSC_VER)

    return ::_stricmp(s1,s2);
#elif defined( __GNUC__ )

    return ::strcasecmp(s1,s2);
#else*/
    char c1, c2;
    do  {
        c1 = tolower(*s1++);
        c2 = tolower(*s2++);
    }
    while ( c1 && (c1 == c2) );
    return c1 - c2;
//#endif
Run Code Online (Sandbox Code Playgroud)

在 中做类似的事情ASSIMP_strincmp

接下来,它会抛出一个关于::_fullpathin的错误DefaultIOSystem.cpp。我对此的“修复”只是使用注释掉此函数中除后备选项之外的所有内容:

    ai_assert(in && _out);
//    char* ret;
//#if defined( _MSC_VER ) || defined( __MINGW32__ )
//    ret = ::_fullpath( _out, in, PATHLIMIT );
//#else
    // use realpath
//    ret = realpath(in, _out);
//#endif
//    if(!ret) {
        // preserve the input path, maybe someone else is able to fix
        // the path before it is accessed (e.g. our file system filter)
//        DefaultLogger::get()->warn("Invalid path: "+std::string(in));
        strcpy(_out,in);
//    }
Run Code Online (Sandbox Code Playgroud)

它还抱怨 snprintf 未定义。编辑StringUtils.h并更改以下 #define 以在 snprintf 之前添加下划线:

#   define ai_snprintf _snprintf
Run Code Online (Sandbox Code Playgroud)

还有一个关于 ::atof 未定义的错误。您可以通过添加来修复此问题

#include <cstdlib>
Run Code Online (Sandbox Code Playgroud)

到 StringUtils.h

这应该可以构建它,但会出现链接错误Exporter.cpp(这可能是由于我的特定 CMake 设置,因为我禁用了几乎所有模型格式)。我通过注释掉 的定义gExporters并将其替换为以下内容来修复它:

Exporter::ExportFormatEntry* gExporters = 0;
Run Code Online (Sandbox Code Playgroud)

此后它构建并运行良好。库文件放在该code文件夹中。将 libassimp.dll.a 放在 lib 构建路径中,将 libassimp.dll 放在可执行文件的路径中。

当然,您也可以通过使用 VisualStudio 来实现它(我没有这样做,因为我懒得安装它)或在 Linux 上构建(我之前这样做过,并且第一次构建得很好,但我需要这样做Windows 端口)。