Eclipse CDT 无法识别 Linux CLOCK_PROCESS_CPUTIME_ID
Posted
技术标签:
【中文标题】Eclipse CDT 无法识别 Linux CLOCK_PROCESS_CPUTIME_ID【英文标题】:Linux CLOCK_PROCESS_CPUTIME_ID not being recognized in Eclipse CDT 【发布时间】:2013-06-22 13:39:34 【问题描述】:Eclipse 无法识别以下代码中的“CLOCK_PROCESS_CPUTIME_ID”。操作系统是 Ubuntu,我使用的是英特尔编译器。代码执行,但语法错误突出显示。在代码下方,我展示了我的构建“脚本”。有人可以帮我解决语法高亮问题吗?
#include <iostream>
#include <time.h>
using namespace std;
timespec diff(timespec start, timespec end);
int main()
timespec time1, time2;
char b = 'A';
bool result;
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time1); //Eclipse highlights as error
result = (b < 58 & b > 47);
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &time2); //Eclipse highlights as error
cout<<diff(time1,time2).tv_sec<<":"<<diff(time1,time2).tv_nsec<<endl;
cout << result << endl;
return 0;
timespec diff(timespec start, timespec end)
timespec temp;
if ((end.tv_nsec-start.tv_nsec)<0)
temp.tv_sec = end.tv_sec-start.tv_sec-1;
temp.tv_nsec = 1000000000+end.tv_nsec-start.tv_nsec;
else
temp.tv_sec = end.tv_sec-start.tv_sec;
temp.tv_nsec = end.tv_nsec-start.tv_nsec;
return temp;
这是我的构建脚本:
icc -E -P -v -dM /home/r/workspace/.metadata/.plugins/org.eclipse.cdt.make.core/specs.cpp
icc version 13.1.0 (gcc version 4.6.0 compatibility)
/opt/intel/composer_xe_2013.2.146/bin/intel64/mcpcom -_g -mP3OPT_inline_alloca -D__HONOR_STD -D__ICC=1310 -D__INTEL_COMPILER=1310 -D__PTRDIFF_TYPE__=long "-D__SIZE_TYPE__=unsigned long" -D__WCHAR_TYPE__=int "-D__WINT_TYPE__=unsigned int" "-D__INTMAX_TYPE__=long int" "-D__UINTMAX_TYPE__=long unsigned int" -D__LONG_MAX__=9223372036854775807L -D__QMSPP_ -D__OPTIMIZE__ -D__NO_MATH_INLINES -D__NO_STRING_INLINES -D__NO_INLINE__ -D__GNUC_GNU_INLINE__ -D__GNUG__=4 -D__GNUC__=4 -D__GNUC_MINOR__=6 -D__GNUC_PATCHLEVEL__=0 -D__LP64__ -D_LP64 -D_GNU_SOURCE=1 -D__DEPRECATED=1 -D__GXX_WEAK__=1 -D__GXX_ABI_VERSION=1002 "-D__USER_LABEL_PREFIX__= " -D__REGISTER_PREFIX__= -D__INTEL_RTTI__ -D__EXCEPTIONS=1 -D__unix__ -D__unix -D__linux__ -D__linux -D__gnu_linux__ -B -Dunix -Dlinux "-_Asystem(unix)" -D__ELF__ -D__x86_64 -D__x86_64__ "-_Acpu(x86_64)" "-_Amachine(x86_64)" -D_MT -D__INTEL_COMPILER_BUILD_DATE=20130121 -D__INTEL_OFFLOAD -D__i686 -D__i686__ -D__pentiumpro -D__pentiumpro__ -D__pentium4 -D__pentium4__ -D__tune_pentium4__ -D__SSE2__ -D__SSE__ -D__MMX__ -_k -_8 -_l -_a -_b -P --gnu_version=460 -_W5 --gcc-extern-inline -p --bool -tused -mGLOB_eh_linux -x --dM --multibyte_chars --array_section --simd --simd_func --offload_mode=1 --offload_target_names=mic,MIC --bool -mP1OPT_print_version=FALSE -mP1OPT_version=13.0-intel64 /home/h/workspace/.metadata/.plugins/org.eclipse.cdt.make.core/specs.cpp
#include "..." search starts here:
#include <...> search starts here:
/opt/intel/composer_xe_2013.2.146/compiler/include/intel64
/opt/intel/composer_xe_2013.2.146/compiler/include
/usr/include/c++/4.6
/usr/include/c++/4.6/x86_64-linux-gnu
/usr/include/c++/4.6/backward
/usr/local/include
/usr/lib/gcc/x86_64-linux-gnu/4.6/include
/usr/lib/gcc/x86_64-linux-gnu/4.6/include-fixed
/usr/include
/usr/include/x86_64-linux-gnu
End of search list.
#define __SIGNED_CHARS__ 1
#define __PRAGMA_REDEFINE_EXTNAME 1
#define __DATE__ "Jun 22 2013"
#define __TIME__ "14:35:06"
#define __STDC__ 1
#define __cilk 200
#define __cplusplus 1
#define __STDC_HOSTED__ 1
#define _WCHAR_T 1
#define _BOOL 1
#define __ARRAY_OPERATORS 1
#define __RTTI 1
#define __PLACEMENT_DELETE 1
#define __EDG_RUNTIME_USES_NAMESPACES 1
#define __EDG_IA64_ABI 1
#define __LONG_DOUBLE_SIZE__ 80
#define __VARIADIC_TEMPLATES 1
#define __EDG__ 1
#define __EDG_VERSION__ 404
#define __EDG_SIZE_TYPE__ unsigned long
#define __EDG_PTRDIFF_TYPE__ long
#define __DECIMAL_BID_FORMAT__ 1
#define __DEC32_MAX__ 9.999999E96DF
#define __DEC64_MAX__ 9.999999999999999E384DD
#define __DEC128_MAX__ 9.999999999999999999999999999999999E6144DL
#define __DEC32_MANT_DIG__ 7
#define __DEC64_MANT_DIG__ 16
#define __DEC128_MANT_DIG__ 34
#define __DEC32_MIN_EXP__ -95
#define __DEC64_MIN_EXP__ -383
#define __DEC128_MIN_EXP__ -6143
#define __DEC32_MAX_EXP__ 96
#define __DEC64_MAX_EXP__ 384
#define __DEC128_MAX_EXP__ 6144
#define __DEC32_EPSILON__ 1E-6DF
#define __DEC64_EPSILON__ 1E-15DD
#define __DEC128_EPSILON__ 1E-33DL
#define __DEC32_MIN__ 1E-95DF
#define __DEC64_MIN__ 1E-383DD
#define __DEC128_MIN__ 1E-6143DL
#define __DEC32_SUBNORMAL_MIN__ 0.000001E-95DF
#define __DEC64_SUBNORMAL_MIN__ 0.000000000000001E-383DD
#define __DEC128_SUBNORMAL_MIN__ 0.000000000000000000000000000000001E-6143DL
#define __DBL_DIG__ 15
#define __DBL_MAX_10_EXP__ 308
#define __DBL_MIN_10_EXP__ -307
#define __DBL_HAS_DENORM__ 1
#define __FLT_DIG__ 6
#define __FLT_MAX_10_EXP__ 38
#define __FLT_MIN_10_EXP__ -37
#define __FLT_RADIX__ 2
#define __FLT_HAS_DENORM__ 1
#define __INT_MAX__ 2147483647
#define __LDBL_DIG__ 18
#define __LDBL_HAS_INFINITY__ 1
#define __LDBL_HAS_QUIET_NAN__ 1
#define __LDBL_MAX_10_EXP__ 4932
#define __LDBL_MIN_10_EXP__ -4931
#define __LDBL_HAS_DENORM__ 1
#define __DBL_HAS_INFINITY__ 1
#define __DBL_HAS_QUIET_NAN__ 1
#define __DECIMAL_DIG__ 21
#define __FINITE_MATH_ONLY__ 0
#define __FLT_HAS_INFINITY__ 1
#define __FLT_HAS_QUIET_NAN__ 1
#define __SCHAR_MAX__ 127
#define __SHRT_MAX__ 32767
#define __WCHAR_MAX__ 2147483647
#define __CHAR_BIT__ 8
#define __DBL_MANT_DIG__ 53
#define __DBL_MAX_EXP__ 1024
#define __TARG_DBL_MAX_EXP__ 1024
#define __DBL_MIN_EXP__ -1021
#define __FLT_MANT_DIG__ 24
#define __FLT_MAX_EXP__ 128
#define __FLT_MIN_EXP__ -125
#define __LDBL_MANT_DIG__ 64
#define __LDBL_MAX_EXP__ 16384
#define __LDBL_MIN_EXP__ -16381
#define __DBL_DENORM_MIN__ 4.9406564584124654e-324
#define __DBL_EPSILON__ 2.2204460492503131e-16
#define __DBL_MAX__ 1.7976931348623157e+308
#define __DBL_MIN__ 2.2250738585072014e-308
#define __FLT_DENORM_MIN__ 1.40129846e-45F
#define __FLT_EPSILON__ 1.19209290e-7F
#define __FLT_MAX__ 3.40282347e+38F
#define __FLT_MIN__ 1.17549435e-38F
#define __LDBL_DENORM_MIN__ 3.64519953188247460253e-4951L
#define __LDBL_EPSILON__ 1.08420217248550443401e-19L
#define __LDBL_MAX__ 1.18973149535723176502e+4932L
#define __LDBL_MIN__ 3.36210314311209350626e-4932L
#define __LONG_LONG_MAX__ 0x7fffffffffffffff
#define __SIZEOF_DOUBLE__ 8
#define __SIZEOF_FLOAT__ 4
#define __SIZEOF_INT__ 4
#define __SIZEOF_LONG__ 8
#define __SIZEOF_LONG_DOUBLE__ 16
#define __SIZEOF_LONG_LONG__ 8
#define __SIZEOF_POINTER__ 8
#define __SIZEOF_PTRDIFF_T__ 8
#define __SIZEOF_SHORT__ 2
#define __SIZEOF_SIZE_T__ 8
#define __SIZEOF_WCHAR_T__ 4
#define __SIZEOF_WINT_T__ 4
#define __INTMAX_MAX__ 0x7fffffffffffffff
#define __UINTMAX_MAX__ 0xffffffffffffffff
#define __SIZE_MAX__ 0xffffffffffffffff
#define __BIGGEST_ALIGNMENT__ 32
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_1 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_2 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_4 1
#define __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 1
#define __GXX_RTTI 1
#define __VERSION__ "Intel(R) C++ g++ 4.6 mode"
#define __HONOR_STD 1
#define __ICC 1310
#define __INTEL_COMPILER 1310
#define __PTRDIFF_TYPE__ long
#define __SIZE_TYPE__ unsigned long
#define __WCHAR_TYPE__ int
#define __WINT_TYPE__ unsigned int
#define __INTMAX_TYPE__ long int
#define __UINTMAX_TYPE__ long unsigned int
#define __LONG_MAX__ 9223372036854775807L
#define __QMSPP_ 1
#define __OPTIMIZE__ 1
#define __NO_MATH_INLINES 1
#define __NO_STRING_INLINES 1
#define __NO_INLINE__ 1
#define __GNUC_GNU_INLINE__ 1
#define __GNUG__ 4
#define __GNUC__ 4
#define __GNUC_MINOR__ 6
#define __GNUC_PATCHLEVEL__ 0
#define __LP64__ 1
#define _LP64 1
#define _GNU_SOURCE 1
#define __DEPRECATED 1
#define __GXX_WEAK__ 1
#define __GXX_ABI_VERSION 1002
#define __USER_LABEL_PREFIX__
#define __REGISTER_PREFIX__
#define __INTEL_RTTI__ 1
#define __EXCEPTIONS 1
#define __unix__ 1
#define __unix 1
#define __linux__ 1
#define __linux 1
#define __gnu_linux__ 1
#define unix 1
#define linux 1
#define __ELF__ 1
#define __x86_64 1
#define __x86_64__ 1
#define _MT 1
#define __INTEL_COMPILER_BUILD_DATE 20130121
#define __INTEL_OFFLOAD 1
#define __i686 1
#define __i686__ 1
#define __pentiumpro 1
#define __pentiumpro__ 1
#define __pentium4 1
#define __pentium4__ 1
#define __tune_pentium4__ 1
#define __SSE2__ 1
#define __SSE__ 1
#define __MMX__ 1
【问题讨论】:
CLOCK_PROCESS_CPUTIME_ID
定义在哪里?
@Massa 我只是 Linux 的初学者,但我相信它是用于原生 C/C++ 函数的某种操作系统结构?正如我所说,代码执行:s
好吧,试试#include <ctime>
而不是time.h
;也许你的eclipse安装有问题。今天晚些时候我会试试的。
@Massa 仍然不起作用。如果您以后可以尝试,将不胜感激:)
我安装了 Eclipse(JunoCDT,通过 Pulse),创建了一个新项目,但这里没有显示错误……抱歉,我帮不上忙。
【参考方案1】:
好的,要解决这个问题,我必须进入我的项目设置“索引器”,并且有一个您“预先”索引的头文件列表。我在此列表中添加了“time.h”,然后重新构建了项目。
完全不知道为什么需要这样做?!
【讨论】:
以上是关于Eclipse CDT 无法识别 Linux CLOCK_PROCESS_CPUTIME_ID的主要内容,如果未能解决你的问题,请参考以下文章
程序无法启动,因为缺少 cygwin1.dll...在 Eclipse CDT 中