strncasecmp 和 strcasecmp 尚未声明 [英] strncasecmp and strcasecmp has not been declared

查看:80
本文介绍了strncasecmp 和 strcasecmp 尚未声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to compile Assimp with MinGW in Code::Blocks, but I get the following errors.

\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|

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

While searching I've found out that the two functions in question (strcasecmp and strncasecmp) are in fact declared in string.h which is included in the header of StringComparison.h. I've also managed to get strings.h, the file which they originally belong to, but including that didn't solved the issue either.

在搜索这个网站时,我发现我并不是唯一一个在这个问题上苦苦挣扎的人.我发现的另一个解决方案建议使用定义语句,因为函数的名称可能略有不同,但这也无济于事.

While searching this site I've found out that I'm not the only one struggling with this issue. Another solution I've found suggested to use define statements, because the functions might have a slightly different name, but that didn't helped either.

推荐答案

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

I just encountered this exact same problem, and this question came up during a Google search for the solution, so I'll document my dodgy solution here:

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

In the end I got it going just by making multiple small edits to the Assimp source code. Solving the string problem isn't enough to get it to work because it just fails later in the build. I'll list the edits I made below. I recommend making them one at a time and then rebuilding, just in case for whatever reason with your setup some of them aren't required. Note that you can't do model exporting with this solution because of the last edit (to Exporter.cpp) if you really need that you'll have to figure out another way to fix the link errors.

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

It's not a clean solution and it will probably be superceded by a future version of Assimp, at which point I will just delete it. This is for assimp-3.3.1, built with MinGW:

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

In StringComparison.h, edit the ASSIMP_stricmp function, commenting out everything except the else clause of the #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

ASSIMP_strincmp中做类似的事情.

接下来,它会在DefaultIOSystem.cpp 中抛出一个关于::_fullpath 的错误.我对此的修复"只是在此功能中使用注释掉后备选项之外的所有内容:

Next, it throws up an error about ::_fullpath in DefaultIOSystem.cpp. My "fix" for this was just to use comment out everything other the fallback option in this function:

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

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

It also complains about snprintf being undefined. Edit StringUtils.h to change the following #define to add an underscore before snprintf:

#   define ai_snprintf _snprintf

还有一个关于 ::atof 未定义的错误.您可以通过添加

There's also an error about ::atof not being defined. You can fix this by adding

#include <cstdlib>

到 StringUtils.h

to StringUtils.h

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

This should get it building but there will be a link error in Exporter.cpp (this might be due to my specific CMake setttings because I disabled almost all model formats). I fixed it by commenting out the definition of gExporters and replacing it with this:

Exporter::ExportFormatEntry* gExporters = 0;

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

After this it built and ran fine. The library files are placed in the code folder. Place libassimp.dll.a in your lib build path and libassimp.dll in the path of your executable.

当然,你也可以通过使用 VisualStudio(我没有,因为我懒得安装它)或通过在 Linux 上构建(我以前做过这个并且它首先构建得很好,但我需要做一个Windows端口).

Of course, you can also get it going by using VisualStudio instead (I didn't because I couldn't be bothered installing it) or by building on Linux (I did this previously and it built fine first go, but I needed to do a Windows port).

这篇关于strncasecmp 和 strcasecmp 尚未声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆