1
votes

is it possible to port Eigen, a C++ template library for linear algebra, to IAR workbench for ARM. I have tried to do this while but am getting following compile errors

Error[Pe337]: linkage specification is incompatible with previous "__nounwind __iar_builtin_get_CONTROL" (declared at line 58 of "C:\Program Files (x86)\IAR Systems\Embedded Workbench 8.3\arm\inc\c\iccarm_builtin.h") C:\Program Files (x86)\IAR Systems\Embedded Workbench 8.3\arm\CMSIS\Core\Include\cmsis_gcc.h 151

This is the entire error I get when I use the preprocessors

__GNUC__
__arm__

if I dont use these preprocessors I get an error from a #error preprocessor from the Eigen file Macros.h

"error Please tell me what is the equivalent of attribute((aligned(n))) for your compiler"

#if (defined __CUDACC__)
  #define EIGEN_ALIGN_TO_BOUNDARY(n) __align__(n)
#elif EIGEN_COMP_GNUC || EIGEN_COMP_PGI || EIGEN_COMP_IBM || EIGEN_COMP_ARM
  #define EIGEN_ALIGN_TO_BOUNDARY(n) __attribute__((aligned(n)))
#elif EIGEN_COMP_MSVC
  #define EIGEN_ALIGN_TO_BOUNDARY(n) __declspec(align(n))
#elif EIGEN_COMP_SUNCC
  // FIXME not sure about this one:
  #define EIGEN_ALIGN_TO_BOUNDARY(n) __attribute__((aligned(n)))
#else
  //#define EIGEN_ALIGN_TO_BOUNDARY(n) __declspec(align(n))
  #error Please tell me what is the equivalent of __attribute__((aligned(n))) for your compiler
#endif

I have it working for visual c++ but not IAR. All includes are added.

These errors change based on the preprocessors I use to try to configure Eigen. Is it possible to use Eigen with IAR?

2
The __iar_builtin_get_CONTROL function name sounds more like IAR issue than Eigen issue. (I don't know what Eigen is, so I may be wrong) Are you perhaps using IAR support headers that are for different version of IAR than what you are using? - user694733
I dont believe I am using the wrong support headers. I haven't changed anything there. How would I be sure though? when I remove Eigen, everything works fine again. - Hadi Jaber
What header file do you get this error from, and is that file part of Eigen? (In the future, please always include complete error messages in your posts) - user694733
I am not familiar with this IAR version, but it would seem odd that you'd use cmsis_gcc.h file. IAR is not GCC compiler. Perhaps you have chosen wrong cmsis version which is intended for gcc and not iar. (Also, please edit your error messages in to your question. They are hard to read on comments.) - user694733
Can you check if the master branch of Eigen works (maybe in C++11 mode)? If you want your local version to work, you could try replacing the #error line by an empty macro #define EIGEN_ALIGN_TO_BOUNDARY(n) (or look up your compiler documentation what you need to write to statically align memory). Furthermore, you should compile with EIGEN_DONT_ALIGN_STATICALLY (or EIGEN_DONT_ALIGN). - chtz

2 Answers

1
votes

To add to @chtz answer, here's how I got the EIGEN_ALIGN_TO_BOUNDARY macro to work with IAR, in a way that is consistent with the eigen library:

1: add this to top of Macros.h to identify the IAR ARM compiler

/// \internal EIGEN_COMP_ICCARM set to 1 if the compiler is IAR eWARM
#if defined(__ICCARM__)
    #define EIGEN_COMP_ICCARM 1
#else
    #define EIGEN_COMP_ICCARM 0
#endif

2: add this case to where EIGEN_ALIGN_TO_BOUNDARY(n) is defined in Macros.h

 #elif EIGEN_COMP_ICCARM
      #define IAR_STRINGIFY(a) #a
      #define IAR_ALIGN_STR(n) IAR_STRINGIFY(data_alignment=n)
      #define EIGEN_ALIGN_TO_BOUNDARY(n) _Pragma(IAR_ALIGN_STR(n))

EIGEN_ALIGN_TO_BOUNDARY(n) should now correctly expand to _Pragma("data_alignment=n")

0
votes

I have now gotten it to build and run. Thank you @chtz for the EIGEN_DONT_ALIGN macro suggestion. This is how I did it. I am unsure however what repercussions this has on the library itself, as in what features this may take away. I did this:

  1. include the directory to where you installed Eigen as the additional includes.
  2. in lines 86, 105, 125, 145 in file DenseStorage.h change the lines EIGEN_ALIGN_TO_BOUNDARY(8) T array[Size];
    to their respective _Pragma("data_alignment=8") T array[Size];
    (pay attention to the number)
  3. in Macros.h , line 665 , comment out the "#error Please tell me what is the"
  4. finally, define the macro EIGEN_DONT_ALIGN in the preprocessor settings.

This is what worked for Eigen 3.3.7