gpt4 book ai didi

C嵌入错误: ‘XXXX’ declared as function returning a function

转载 作者:行者123 更新时间:2023-11-30 16:38:36 26 4
gpt4 key购买 nike

我正在尝试交叉编译 LAPACK 库(fortran)和 C API,LAPACKE 用于裸机嵌入式目标 powerpc-eabi 目标,使用该目标的 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 接口(interface)时会出现此错误。

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)

这样,我的定义就被采纳并应用了适当的修改。

关于C嵌入错误: ‘XXXX’ declared as function returning a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47439914/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com