代码之家  ›  专栏  ›  技术社区  ›  crobar

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

  •  0
  • crobar  · 技术社区  · 8 年前

    我试图使用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)
                          ^
    

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

    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 回复  |  直到 8 年前
        1
  •  0
  •   crobar    8 年前

    实际上,问题是预处理器头文件实际上并没有与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)
    

    有了这个,我的定义被提取出来,并应用了适当的损坏。