gpt4 book ai didi

c++ - 编译器错误 MB_LEN_MAX 的假定值错误

转载 作者:太空宇宙 更新时间:2023-11-04 12:48:08 25 4
gpt4 key购买 nike

我目前正在尝试运行 this image segmentation program ,但是当我尝试编译它时遇到错误。要编译,您只需make,它运行命令

g++ -g -O3 -I. -o segment segment.cpp -lm

但是,它遇到了一个编译错误——它的输出是

In file included from /usr/include/wchar.h:887:0,
from /usr/include/c++/6/cwchar:44,
from /usr/include/c++/6/bits/postypes.h:40,
from /usr/include/c++/6/iosfwd:40,
from /usr/include/c++/6/ios:38,
from /usr/include/c++/6/istream:38,
from /usr/include/c++/6/fstream:38,
from ./pnmfile.h:27,
from segment.cpp:23:
/usr/include/x86_64-linux-gnu/bits/wchar2.h:448:3: error: #error "Assumed value of MB_LEN_MAX wrong"
# error "Assumed value of MB_LEN_MAX wrong"
^~~~~
Makefile:14: recipe for target 'segment' failed
make: *** [segment] Error 1

这里是/usr/include/x86_64-linux-gnu/bits/wchar2.h的相关区域

  /* We would have to include <limits.h> to get a definition of MB_LEN_MAX.
But this would only disturb the namespace. So we define our own
version here. */
#define __WCHAR_MB_LEN_MAX 16
#if defined MB_LEN_MAX && MB_LEN_MAX != __WCHAR_MB_LEN_MAX
# error "Assumed value of MB_LEN_MAX wrong"
#endif
if (__bos (__s) != (size_t) -1 && __WCHAR_MB_LEN_MAX > __bos (__s))
return __wcrtomb_chk (__s, __wchar, __ps, __bos (__s));
return __wcrtomb_alias (__s, __wchar, __ps);
}

以及segment.cpp的相关区域:

#include <cstdio>
#include <cstdlib>
#include <image.h>
#include <misc.h>
#include <pnmfile.h> //<-- Line 23 of segment.cpp, where the error occurs
#include "segment-image.h"

pnmfile.h:

#include <cstdlib>
#include <climits>
#include <cstring>
#include <fstream> //<-- Line 27 of pnmfile.h where the error occurs
#include "image.h"
#include "misc.h"

有谁知道导致此错误的原因(如果是,如何解决)?我正在使用 g++ 6.4.0 运行 Ubuntu 16.04。感谢您提供的任何帮助!

编辑:我已经确认 fstream 确实有效。我编译如下

#include <iostream>
#include <cstdlib>
#include <fstream>

using namespace std;

int main() {
ifstream is("in.txt");
int a, b;
is >> a >> b;
cout << a << endl;
cout << b << endl;
return 0;
}

同样的命令

g++ -g -O3 -I. -o temp.exe temp.cpp -lm

它成功地打印出了从文本文件中读取的两个整数。

最佳答案

您需要包含 limits.h 来自您的 bits/wchar2.h 所在的同一个 libc。如果您查看 latter file 中的评论在您收到的 #error 上方,您会明白为什么 - 它可以防止混合不兼容的头文件。

关于c++ - 编译器错误 MB_LEN_MAX 的假定值错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50357803/

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