ccompiler-errorsfortranc-preprocessorlapacke

C embedded error: ‘XXXX’ declared as function returning a function


I'm attempting to cross-compile the LAPACK library (fortran) and the C API, LAPACKE for bare-metal embedded targets powerpc-eabi target, using the gcc cross compilers for this target. Compiling proceeds but eventually hits this error:

[ 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)
                      ^

This error occurs when building the C interface to LAPACK, LAPACKE.

A post on the LAPACK forums suggests this is a problem with Fortran name mangling, and to add the -DADD_ processor flag. Above I have attempted this, but it makes no difference.

The preprocessor define is used in a header file, copied below:

#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

The error occurs in another header file which uses LAPACK_GLOBAL like so:

#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 );

The lapacke_mangling.h file contents is shown below:

#ifndef LAPACK_HEADER_INCLUDED
#define LAPACK_HEADER_INCLUDED

#endif

The error does not occur when building natively, or when building for another linux target, powerpc-linux-gnu.

Can anyone explain the problem?


Solution

  • Actually the problem was that the preprocessor header file was not actually used with the cmake build system, instead a different header was supposed to be generated by cmake. Cmake did not generate the file corectly (probably because of cross-compilation). The patch below modifies the lapacke CMakeLists to add an option to force the use of this header file.

    --- 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)
    

    With this, my definitions were picked up and the appropriate mangling applied.