C ++库编译错误(例如,size_t未命名类型)

时间:2019-07-17 09:37:48

标签: c++ compiler-errors

compile error

我遇到如下错误:

In file included from /usr/include/stdio.h:74:0,
                 from thread_pool.hpp:4,
                 from master_server.h:4,
                 from master_server.cpp:1:
/usr/include/libio.h:307:3: error: 'size_t' does not name a type
   size_t __pad5;
   ^
/usr/include/libio.h:311:67: error: 'size_t' was not declared in this scope
   char _unused2[15 * sizeof (int) - 4 * sizeof (void *) - sizeof (size_t)];
                                                                   ^
/usr/include/libio.h:339:62: error: 'size_t' has not been declared
 typedef __ssize_t __io_read_fn (void *__cookie, char *__buf, size_t __nbytes);
                                                              ^
/usr/include/libio.h:348:6: error: 'size_t' has not been declared
      size_t __n);
      ^

此列表一直在继续,主要涉及基本库。我的编译器选项是:

g++ -c master_server.cpp -o master_server.o -std=c++11 -Wall -Wextra -L/usr/include/boost -lboost_filesystem -lboost_system -lboost_thread

当我尝试用C ++编译代码时,我收到大量错误,提示无法找到或未声明某些内容。怎么可能出问题了?

-------编辑-------

为获得最低的可复制代码,我尝试了一个简单的Hello World代码:

#include <cstring>
#include <iostream>

int main() {
    char *s = "Hello World";
    std::cout << s << std::endl;
}

这给了我同样的错误:

In file included from /usr/include/c++/4.8.2/cstring:42:0,
                 from hi.cpp:1:
/usr/include/string.h:43:8: error: ‘size_t’ has not been declared
        size_t __n) __THROW __nonnull ((1, 2));
        ^
/usr/include/string.h:46:56: error: ‘size_t’ has not been declared
 extern void *memmove (void *__dest, const void *__src, size_t __n)
                                                        ^
/usr/include/string.h:55:18: error: ‘size_t’ has not been declared
         int __c, size_t __n)
                  ^
/usr/include/string.h:62:42: error: ‘size_t’ has not been declared
 extern void *memset (void *__s, int __c, size_t __n) __THROW __nonnull ((1));
                                          ^
/usr/include/string.h:65:56: error: ‘size_t’ has not been declared
 extern int memcmp (const void *__s1, const void *__s2, size_t __n)
                                                        ^
/usr/include/string.h:72:42: error: ‘size_t’ has not been declared
 extern void *memchr (void *__s, int __c, size_t __n)

0 个答案:

没有答案