error: ‘alarm’ was not declared in this scope 解决

0. 在编译librangetree-v1.2 (C++ 2D 范围树) 的bench出现 “error: ‘alarm’ was not declared in this scope ”错误

[ghui@StuOS bench]$ g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8.0/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../configure --prefix=/usr --libexecdir=/usr/lib --with-gmp=/usr/local/gmp-5.0.5 --with-mpfr=/usr/local/mpfr-2.4.2 --with-mpc=/usr/local/mpc-0.8.1 --with-ppl=/usr/local/ppl-0.11 --with-cloog=/usr/local/cloog-0.16.2 --enable-shared --enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu --enable-languages=c,c++,fortran,go,java,lto,objc,obj-c++ --enable-multilib --disable-bootstrap --with-system-zlib --build=x86_64-linux-gnu --enable-lto --with-cpu=athlon64 --enable-cloog-backend=isl --enable-objc-gc --disable-werror --enable-interwork --with-gnu-ld
Thread model: posix
gcc version 4.8.0 20121004 (experimental) (GCC) 
[ghui@StuOS bench]$ pwd
/home/Ghui/Desktop/librangetree-v1.2/bench
[ghui@StuOS bench]$ ls
countspeed.cpp  example.png  Makefile  mil.cpp  scaling.cpp  timing.h  viz.cpp
[ghui@StuOS bench]$ make
g++ -Wall -Wextra -I ..   countspeed.cpp ../ranget.h timing.h   -o countspeed
g++ -Wall -Wextra -fopenmp -I .. -fopenmp  scaling.cpp ../ranget.h timing.h   -o scaling
scaling.cpp: In function ‘int main()’:
scaling.cpp:70:10: error: ‘alarm’ was not declared in this scope
   alarm(2);
          ^
make: *** [scaling] Error 1

2. 在scaling.cpp包含#include <unistd.h>如下:

#include <unistd.h>
#include "timing.h"
#include <omp.h>
#include <signal.h>


3. 再次编译:

[ghui@StuOS bench]$ make
g++ -Wall -Wextra -fopenmp -I .. -fopenmp  scaling.cpp ../ranget.h timing.h   -o scaling
g++ -Wall -Wextra -I ..   mil.cpp ../ranget.h timing.h   -o mil
[ghui@StuOS bench]$ ls
countspeed  countspeed.cpp  example.png  Makefile  mil  mil.cpp  scaling  scaling.cpp  timing.h  viz.cpp


By iomato

[email protected]

09:50 - 2013-01-05

你可能感兴趣的:(error: ‘alarm’ was not declared in this scope 解决)