Problem with compiling Eigen Library

322 views
Skip to first unread message

riscv21

unread,
Jan 29, 2024, 12:47:39 AM1/29/24
to RISC-V SW Dev
Hi everyone,

I am trying to compile a C++ code using riscv toolchain (riscv64-unknown-elf-g++ 13.2.0). The C++ code includes the following header files, which the compiler could not find:

#include <Eigen/Dense>
#include <Eigen/Sparse>
#include <fftw3.h>

I cloned the Eigen and  fftw3 libraries from the following links:


Then, I included the full path to the required header files.

#include "/home/riscv-gnu-toolchain/test_custom_insts/eigen/Eigen/Dense"
#include "/home/riscv-gnu-toolchain/test_custom_insts/eigen/Eigen/Sparse"
#include "/home/riscv-gnu-toolchain/test_custom_insts/fftw3/api/fftw3.h"

However, using "riscv64-unknown-elf-g++ -std=c++17 main.cpp -o main" command, I'm getting the following errors regarding std. I would appreciate any help to fix these issues. Thank you!

In file included from /home/riscv-gnu-toolchain/test_custom_insts/eigen/Eigen/Core:179,
                 from /home/riscv-gnu-toolchain/test_custom_insts/eigen/Eigen/Dense:1,
                 from shihui.cpp:14:
/home/riscv-gnu-toolchain/test_custom_insts/eigen/Eigen/src/Core/NumTraits.h: In static member function 'static constexpr int Eigen::internal::default_digits_impl<T, false, false>::run()':
/home/riscv-gnu-toolchain/test_custom_insts/eigen/Eigen/src/Core/NumTraits.h:33:16: error: 'log2' has not been declared in 'std'
   33 |     using std::log2;
      |                ^~~~

In file included from /home/riscv-gnu-toolchain/test_custom_insts/eigen/Eigen/Core:19:
/home/riscv-gnu-toolchain/test_custom_insts/eigen/Eigen/src/Core/MathFunctions.h: In static member function 'static Scalar Eigen::internal::expm1_impl<Scalar>::run(const Scalar&)':
/home/riscv-gnu-toolchain/test_custom_insts/eigen/Eigen/src/Core/MathFunctions.h:457:21: error: 'expm1' has not been declared in 'std'
  457 |     EIGEN_USING_STD(expm1);
      |                     ^~~~~

/home/riscv-gnu-toolchain/test_custom_insts/eigen/Eigen/src/Core/util/Macros.h:1072:42: note: in definition of macro 'EIGEN_USING_STD'
 1072 | #define EIGEN_USING_STD(FUNC) using std::FUNC;
      |                                          ^~~~
/home/riscv-gnu-toolchain/test_custom_insts/eigen/Eigen/src/Core/MathFunctions.h: In static member function 'static Scalar Eigen::internal::log1p_impl<Scalar>::run(const Scalar&)':
/home/riscv-gnu-toolchain/test_custom_insts/eigen/Eigen/src/Core/MathFunctions.h:513:21: error: 'log1p' has not been declared in 'std'
  513 |     EIGEN_USING_STD(log1p);
      |                     ^~~~~

/home/riscv-gnu-toolchain/test_custom_insts/eigen/Eigen/src/Core/util/Macros.h:1072:42: note: in definition of macro 'EIGEN_USING_STD'
 1072 | #define EIGEN_USING_STD(FUNC) using std::FUNC;
      |                                          ^~~~

/home/riscv-gnu-toolchain/test_custom_insts/eigen/Eigen/src/Core/MathFunctions.h: In static member function 'static Scalar Eigen::internal::nearest_integer_impl<Scalar, IsInteger>::run_rint(const Scalar&)':
/home/riscv-gnu-toolchain/test_custom_insts/eigen/Eigen/src/Core/MathFunctions.h:943:21: error: 'rint' has not been declared in 'std'
  943 |     EIGEN_USING_STD(rint) return rint(x);
      |                     ^~~~

/home/riscv-gnu-toolchain/test_custom_insts/eigen/Eigen/src/Core/util/Macros.h:1072:42: note: in definition of macro 'EIGEN_USING_STD'
 1072 | #define EIGEN_USING_STD(FUNC) using std::FUNC;
      |                                          ^~~~

/home/riscv-gnu-toolchain/test_custom_insts/eigen/Eigen/src/Core/MathFunctions.h: In static member function 'static Scalar Eigen::internal::nearest_integer_impl<Scalar, IsInteger>::run_round(const Scalar&)':
/home/riscv-gnu-toolchain/test_custom_insts/eigen/Eigen/src/Core/MathFunctions.h:946:21: error: 'round' has not been declared in 'std'
  946 |     EIGEN_USING_STD(round) return round(x);
      |                     ^~~~~

/home/riscv-gnu-toolchain/test_custom_insts/eigen/Eigen/src/Core/util/Macros.h:1072:42: note: in definition of macro 'EIGEN_USING_STD'
 1072 | #define EIGEN_USING_STD(FUNC) using std::FUNC;
      |                                          ^~~~

In file included from /home/riscv-gnu-toolchain/test_custom_insts/eigen/Eigen/Core:180:
/home/riscv-gnu-toolchain/test_custom_insts/eigen/Eigen/src/Core/MathFunctions.h: In function 'T Eigen::numext::absdiff(const T&, const T&) [with T = long double]':
/home/riscv-gnu-toolchain/test_custom_insts/eigen/Eigen/src/Core/MathFunctions.h:1163:10: error: 'fabsl' was not declared in this scope; did you mean 'fabsf'?
 1163 |   return fabsl(x - y);
      |          ^~~~~
      |          fabsf

/home/riscv-gnu-toolchain/test_custom_insts/eigen/Eigen/src/Core/MathFunctions.h: In function 'T Eigen::numext::cbrt(const T&)':
/home/riscv-gnu-toolchain/test_custom_insts/eigen/Eigen/src/Core/MathFunctions.h:1340:19: error: 'cbrt' has not been declared in 'std'
 1340 |   EIGEN_USING_STD(cbrt);

Tommy Murphy

unread,
Jan 29, 2024, 2:46:53 AM1/29/24
to riscv21, RISC-V SW Dev
I don't know for sure but suspect that this may be due to limitations with the C++ support in the RISC-V implementation of Newlib. Similar issues (albeit not the specific ones that you mention here) with that support have been reported in the past here:


Does your code compile ok if you use the Linux/Glibc toolchain (`riscv64-unknown-linux-gnu-g++`)? If so, can you use that or is your target strictly bare-metal? If you must use the bare-metal toolchain then you may need to raise this issue in the upstream Newlib project.

Another option might be to try a bare-metal/picolibc toolchain to see if that standard library works any better but, as far as I recall, support for building that is still in a pending PR so it may not be as straightforward as doing `make picolibc`:

Liviu Ionescu

unread,
Jan 29, 2024, 3:33:09 AM1/29/24
to Tommy Murphy, riscv21, RISC-V SW Dev


> On 29 Jan 2024, at 09:46, Tommy Murphy <tommy_...@hotmail.com> wrote:
>
> may be due to limitations with the C++ support in the RISC-V implementation of Newlib

Hmmm... I did a test and the xPack GNU RISC-V Embedded GCC behaves the same. :-(

% /Users/ilg/Library/xPacks/@xpack-dev-tools/riscv-none-elf-gcc/13.2.0-2.1/.content/bin/riscv-none-elf-g++ -c main.cpp --std=c++20 -march=rv32imafdc -mabi=ilp32d
main.cpp: In function 'int main()':
main.cpp:4:20: error: 'log2' is not a member of 'std'; did you mean 'log'?
4 | float f = std::log2(42.0f);
| ^~~~
| log

The same test on Ubuntu 22 ended with:

$ riscv64-unknown-elf-g++ -c main.cpp --std=c++20 -march=rv32imafdc -mabi=ilp32d
main.cpp:1:10: fatal error: cmath: No such file or directory
1 | #include <cmath>
| ^~~~~~~
compilation terminated.


As far as I know, the `std::` functions are not part of newlib, but of GCC, so I suspect that this is a limitation of the RISC-V GCC, it either has no support for cmath at all, as in Ubuntu, which includes an old 10.x riscv64-unknown-elf-g++), or supports it only partially, as in the recent 13.x riscv-none-elf-gcc.

To make things worse, in exactly the same conditions, the arm-none-eabi-gcc toolchain compiled the std::log2 call, which is weird, since my arm-none-eabi-gcc and riscv-none-elf-g++ use the same build scripts...

Regards,

Liviu

Tommy Murphy

unread,
Jan 29, 2024, 4:20:41 AM1/29/24
to Liviu Ionescu, riscv21, RISC-V SW Dev
As far as I know, the `std::` functions are not part of newlib, but of GCC

Ah, looks like you're correct and my reference to Newlib was misleading. Apologies!


> so I suspect that this is a limitation of the RISC-V GCC, it either has no support for cmath at all, as in Ubuntu, which includes an old 10.x riscv64-unknown-elf-g++), or supports it only partially, as in the recent 13.x riscv-none-elf-gcc.

In which case the correct place to raise this may be the upstream/master GCC project?




riscv21

unread,
Jan 31, 2024, 11:54:23 PM1/31/24
to RISC-V SW Dev, tommy_...@hotmail.com, riscv21, RISC-V SW Dev, i...@livius.net
Thank you everyone for your suggestions!

Using RISC-V Linux toolchain (riscv64-unknown-linux-gnu-g++) helped in fixing the issue.
Reply all
Reply to author
Forward
0 new messages