gpt4 book ai didi

c++ - strncasecmp 和 strcasecmp 尚未声明

转载 作者:太空狗 更新时间:2023-10-29 22:58:45 27 4
gpt4 key购买 nike

我尝试在 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|

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

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

最佳答案

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

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

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

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

/*#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 的错误。我对此的“修复”只是使用注释掉此函数中除回退选项之外的所有内容:

    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 之前添加下划线:

#   define ai_snprintf _snprintf

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

#include <cstdlib>

到 StringUtils.h

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

Exporter::ExportFormatEntry* gExporters = 0;

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

当然,您也可以改用 VisualStudio(我没有这样做,因为我懒得安装它)或在 Linux 上构建(我以前这样做过,它一开始构建得很好,但我需要做一个 Windows 端口)。

关于c++ - strncasecmp 和 strcasecmp 尚未声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39659331/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com