我在 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 卡?)是 cosmic ray 的受害者,但为了以防万一,我会对硬盘和内存进行全面扫描。
然后,您当然应该重新安装相关的软件包。我认为它是 libc6-dev
,而不是 build-essential
,它是一个仅依赖包,或者 Debian 对它的称呼。
关于包含 header 的 C++ 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34732848/