“#pragma”命令中的变量“未声明”?

时间:2010-07-20 19:29:00

标签: c gcc openmp c-preprocessor

我正在编译Fedora 8盒子上的Blender 3D建模程序from source(使用SCONS)的一个分支,并且遇到了一个错误,我没有遇到在CentOS 5盒子上编译相同的源,我认为它与变量定义有关。错误是:

source/blender/blenkernel/intern/implicit.c: In function ‘mul_bfmatrix_lfvector’:
source/blender/blenkernel/intern/implicit.c:592: error: ‘CLOTH_OPENMP_LIMIT’ undeclared (first use in this function)
source/blender/blenkernel/intern/implicit.c:592: error: (Each undeclared identifier is reported only once
source/blender/blenkernel/intern/implicit.c:592: error: for each function it appears in.)
source/blender/blenkernel/intern/implicit.c: In function ‘cloth_calc_force’:
source/blender/blenkernel/intern/implicit.c:1700: error: ‘CLOTH_OPENMP_LIMIT’ undeclared (first use in this function)

文件implicit.c确实定义了该变量;这是文件的前几行:

#include "MEM_guardedalloc.h"

#include "BKE_cloth.h"

#include "DNA_object_force.h"

#include "BKE_effect.h"
#include "BKE_global.h"
#include "BKE_utildefines.h"

#include "BLI_threads.h"

#define CLOTH_OPENMP_LIMIT 25

#ifdef _WIN32
#include <windows.h>
static LARGE_INTEGER _itstart, _itend;
static LARGE_INTEGER ifreq;

抛出错误的两行是:

#pragma omp parallel sections private(i) if(vcount > CLOTH_OPENMP_LIMIT)

#pragma omp parallel for private(i) if(numverts > CLOTH_OPENMP_LIMIT)

我猜这个错误是由于编译器以及它在编译变量定义时的处理方式,而且由于Fedora 8有点过时,它可能有一些旧版本的某些编译器搞砸了它。任何人都知道如何绕过这个变量显示为“未声明”?

4 个答案:

答案 0 :(得分:1)

该编译器不支持OpenMP。这是第一次提到OpenMP和GCC

2006年3月9日

...所以从GCC 4.2开始,编译器支持OpenMP v2.5规范。

这里的提示非常明确地定义了值,但根据预处理器错误,#pragma ...行无法找到定义。一旦你意识到代码使用的是非标准的#pragma编译器指令,编译器就会成为主要的嫌疑人。

答案 1 :(得分:0)

很难说,但要么:

  1. 将定义CLOTH_OPENMP_LIMIT更改为其数值并重新编译
  2. 检查include语句以确保CLOTH_OPENMP_LIMIT实际上已正确定义。
  3. 如果仍然无效,则编译器上的OpenMP API已过期,未安装或无法正常工作。

答案 2 :(得分:0)

看起来由于某种原因,CLOTH_OPENMP_LIMIT实际上并未被定义。您可以在生成错误的行之前对此进行测试:

#ifndef CLOTH_OPENMP_LIMIT
#error "Ooops, CLOTH_OPENMP_LIMIT not defined!"
#endif

常见的原因是它依赖于定义的其他预处理器定义,或者在预期时不包括标题。

答案 3 :(得分:0)

我想在4.1版本出现的时候,gcc中的OpenMP仍然具有实验性。如果使用数字常量替换OpenMP pragma中的宏名称会发生​​什么?我不太确定标准对于pragma中的宏替换有什么说法,也许这个旧版本的gcc与新版本有不同的策略。

相关问题