C嵌入错误:'XXXX'声明为函数返回函数

时间:2017-11-22 16:44:57

标签: c compiler-errors fortran c-preprocessor lapacke

我尝试使用gcc交叉编译器为此目标交叉编译LAPACK库(fortran)和C API,LAPACKE用于裸机嵌入式目标powerpc-eabi目标。编译收益但最终会遇到此错误:

[ 44%] Building C object LAPACKE/CMakeFiles/lapacke.dir/src/lapacke_cbbcsd.c.obj
cd /home/rcrozier/build/powerpc-eabi/lapack/LAPACKE && /usr/local/powerpc-eabi/bin/powerpc-eabi-gcc  -DADD_ -mcpu=750 -I/home/rcrozier/src/fast-v8-hg/cross-dependancies/lapack-3.6.0/LAPACKE/include    -o CMakeFiles/lapacke.dir/src/lapacke_cbbcsd.c.obj   -c /home/rcrozier/src/fast-v8-hg/cross-dependancies/lapack-3.6.0/LAPACKE/src/lapacke_cbbcsd.c
In file included from /home/rcrozier/src/fast-v8-hg/cross-dependancies/lapack-3.6.0/LAPACKE/include/lapacke_utils.h:37:0,
                 from /home/rcrozier/src/fast-v8-hg/cross-dependancies/lapack-3.6.0/LAPACKE/src/lapacke_cbbcsd.c:34:
/home/rcrozier/src/fast-v8-hg/cross-dependancies/lapack-3.6.0/LAPACKE/include/lapacke.h:145:22: error: ‘LAPACK_GLOBAL’ declared as function returning a function
 #define LAPACK_lsame LAPACK_GLOBAL(lsame,LSAME)
                      ^

构建LAPACK,LAPACKE的C接口时会发生此错误。

A post on the LAPACK forums表明这是Fortran名称修改的问题,并添加了-DADD_处理器标志。上面我试过这个,但没有区别。

预处理器定义用于头文件中,复制如下:

#ifndef LAPACK_HEADER_INCLUDED
#define LAPACK_HEADER_INCLUDED

#ifndef LAPACK_GLOBAL
#if defined(LAPACK_GLOBAL_PATTERN_LC) || defined(ADD_)
#define LAPACK_GLOBAL(lcname,UCNAME)  lcname##_
#elif defined(LAPACK_GLOBAL_PATTERN_UC) || defined(UPPER)
#define LAPACK_GLOBAL(lcname,UCNAME)  UCNAME
#elif defined(LAPACK_GLOBAL_PATTERN_MC) || defined(NOCHANGE)
#define LAPACK_GLOBAL(lcname,UCNAME)  lcname
#else
#define LAPACK_GLOBAL(lcname,UCNAME)  lcname##_
#endif
#endif

#endif

错误发生在使用LAPACK_GLOBAL的另一个头文件中,如下所示:

#include "lapacke_mangling.h"

#define LAPACK_lsame LAPACK_GLOBAL(lsame,LSAME)
lapack_logical LAPACK_lsame( char* ca,  char* cb,
                              lapack_int lca, lapack_int lcb );

lapacke_mangling.h文件内容如下所示:

#ifndef LAPACK_HEADER_INCLUDED
#define LAPACK_HEADER_INCLUDED

#endif

在本机构建或构建另一个Linux目标powerpc-linux-gnu时,不会发生错误。

有人可以解释这个问题吗?

1 个答案:

答案 0 :(得分:0)

实际上问题是预处理器头文件实际上并没有与cmake构建系统一起使用,而是应该由cmake生成不同的头。 Cmake没有核心生成文件(可能是因为交叉编译)。下面的补丁修改了lapacke CMakeLists以添加一个强制使用此头文件的选项。

--- CMakeLists.txt  2017-11-30 12:07:46.007080017 +0000
+++ newCMakeLists.txt   2017-11-30 12:06:54.491078643 +0000
@@ -3,11 +3,18 @@

 set(LAPACK_INSTALL_EXPORT_NAME lapacke-targets)

+option(FORCE_LAPACKE_MANGLING_WITH_FLAGS "Force the use of the lapack_mangling_with_flags.h header rather than automatic detection" OFF)
+
 # Create a header file netlib.h for the routines called in my C programs
-include(FortranCInterface)
-FortranCInterface_HEADER( ${CMAKE_CURRENT_SOURCE_DIR}/include/lapacke_mangling.h
-                          MACRO_NAMESPACE "LAPACK_"
-                          SYMBOL_NAMESPACE "LAPACK_" )
+if (FORCE_LAPACKE_MANGLING_WITH_FLAGS)
+    # copy the lapacke_mangling_with_flags.h to lapacke_mangling.h
+    configure_file(${CMAKE_CURRENT_SOURCE_DIR}/include/lapacke_mangling_with_flags.h ${CMAKE_CURRENT_SOURCE_DIR}/include/lapacke_mangling.h)
+else (FORCE_LAPACKE_MANGLING_WITH_FLAGS)
+    include(FortranCInterface)
+    FortranCInterface_HEADER( ${CMAKE_CURRENT_SOURCE_DIR}/include/lapacke_mangling.h
+                              MACRO_NAMESPACE "LAPACK_"
+                              SYMBOL_NAMESPACE "LAPACK_" )
+endif (FORCE_LAPACKE_MANGLING_WITH_FLAGS)

 # Old way to detect mangling
 #include(FortranMangling)

有了这个,我的定义被选中并适用了适当的修改。