包含 headers 的 C++ 错误

C++ error with included headers

我在 Linux 操作系统 (LUbuntu 15.05) 上编译 C++ 代码时遇到问题。

我在 XUbuntu 14.10、Arch 和 Gentoo 上编译的相同代码 Linux。一切都很好。现在我在家用台式电脑上安装了 LUbuntu,当我开始 make 时,我给出了这个错误:

g++ -O2 -Wall -o main.o main.cpp
In file included from /usr/include/i386-linux-gnu/c++/5/bits/gthr-default.h:35:0,
                 from /usr/include/i386-linux-gnu/c++/5/bits/gthr.h:148,
                 from /usr/include/c++/5/ext/atomicity.h:35,
                 from /usr/include/c++/5/bits/ios_base.h:39,
                 from /usr/include/c++/5/ios:42,
                 from /usr/include/c++/5/ostream:38,
                 from /usr/include/c++/5/iostream:39,
                 from main.h:8,
                 from main.cpp:1:
/usr/include/pthread.h:1058:55: error: ‘_lock’ was not declared in this scope
 extern int pthread_spin_trylock (pthread_spinlock_t *[_lock)
                                                       ^
/usr/include/pthread.h:1058:54: error: expected ‘,’ or ‘...’ before ‘[’ token
 extern int pthread_spin_trylock (pthread_spinlock_t *[_lock)
                                                      ^
Makefile:30: recipe for target 'main.o' failed
make: *** [main.o] Error 1

这是我的 main.h 文件:

#ifndef MAIN_H
#define MAIN_H
#include <SDL/SDL.h>
#include <SDL/SDL_opengl.h>
#include <SDL/SDL_mixer.h>
#include <SDL/SDL_image.h>
#include <iostream>
#include <vector>

#endif  // MAIN_H

我不知道该怎么办。我安装 build-essential。 请帮忙。

我查看了系统中的那个文件,非常接近第 1058 行,有这一行:

extern int pthread_spin_trylock (pthread_spinlock_t *__lock)

奇怪...您的行有 [ 而不是预期的 _...

如果您查看 _[ 的 ascii 值,它们是:

_: 95 = 0x5F = 01011111
[: 91 = 0x5B = 01011011

看,只有一点点不同。也许您的硬盘 (sd-card?) 是 cosmic ray 的受害者,但我会全面扫描 hard-disk 和内存,以防万一。

然后,当然要重新安装相关的包了。我认为它是 libc6-dev,而不是 build-essential,那是一个 dependency-only 包,或者任何 Debian 调用它的东西。