C embedded error: ‘XXXX’ declared as function returning a function
C embedded error: ‘XXXX’ declared as function returning a function
我正在尝试交叉编译 LAPACK 库 (fortran) 和 C API,用于裸机嵌入式目标 powerpc-eabi 目标的 LAPACKE,为此目标使用 gcc 交叉编译器。编译继续但最终遇到此错误:
[ 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
。
谁能解释一下这个问题?
实际上,问题在于预处理器头文件实际上并未与 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)
有了这个,我的定义被拾取并应用了适当的修改。
我正在尝试交叉编译 LAPACK 库 (fortran) 和 C API,用于裸机嵌入式目标 powerpc-eabi 目标的 LAPACKE,为此目标使用 gcc 交叉编译器。编译继续但最终遇到此错误:
[ 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
。
谁能解释一下这个问题?
实际上,问题在于预处理器头文件实际上并未与 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)
有了这个,我的定义被拾取并应用了适当的修改。