包含标头的C++错误

C++ error with included headers

本文关键字:错误 C++ 包含标      更新时间:2023-10-16

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

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

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

这是我的主.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卡?)是宇宙射线的受害者,但我会对硬盘和内存进行全面扫描,以防万一。

然后,您当然应该重新安装相关的软件包。我认为是libc6-dev,而不是build-essential,这是一个仅依赖的包,或者Debian称之为什么。