构建使用 Eigen(用于线性代数的 C++ 模板库)的项目时出现编译器错误
Posted
技术标签:
【中文标题】构建使用 Eigen(用于线性代数的 C++ 模板库)的项目时出现编译器错误【英文标题】:Compiler errors while building a project which uses Eigen, the C++ template library for linear algebra 【发布时间】:2010-07-20 08:05:08 【问题描述】:在我的项目中,我将 Eigen C++ 库用于线性代数,ONLY 当我为 ARM NEON 打开矢量化标志 (mfpu=neon -mfloat-abi=softfp) 时,我得到编译器错误。我无法理解出了什么问题。我是否需要在 Eigen 库中为 ARM NEON 启用任何预处理器指令?
main.c
#include<iostream>
#include <Eigen/Core>
// import most common Eigen types
using namespace Eigen;
int main(int, char *[])
Matrix4f m3;
m3 << 1, 2, 3, 0, 4, 5, 6, 0, 7, 8, 9, 0, 0, 0, 0, 0;
Matrix4f m4;
asm("#begins here");
m4 = m3*m3;
asm("#ends here");
std::cout << "m3\n" << m3 << "\nm4:\n"
<< m4 << std::endl;
std::cout << "DONE!!";
制作文件
main: main.cpp
g++ -mfpu=neon -mfloat-abi=softfp -I /home/ubuntu/Documents/eigen/ main.cpp -o main
错误
ubuntu@ubuntu-desktop:~/Documents/mat_mul$ make
g++ -mfpu=neon -mfloat-abi=softfp -I /home/ubuntu/Documents/eigen/ main.cpp -o main
In file included from /home/ubuntu/Documents/eigen/Eigen/Core:227,
from main.cpp:2:
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h: In function ‘typename Eigen::ei_packet_traits<T>::type Eigen::ei_pload(const Scalar*) [with Scalar = float]’:
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h:163: error: cannot convert ‘const float*’ to ‘const float32_t*’ for argument ‘1’ to ‘__builtin_neon_sf __vector__ vld1q_f32(const float32_t*)’
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h: In function ‘typename Eigen::ei_packet_traits<T>::type Eigen::ei_ploadu(const Scalar*) [with Scalar = float]’:
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h:166: error: cannot convert ‘const float*’ to ‘const float32_t*’ for argument ‘1’ to ‘__builtin_neon_sf __vector__ vld1q_f32(const float32_t*)’
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h: In function ‘void Eigen::ei_pstore(Scalar*, const Packet&) [with Scalar = float, Packet = __builtin_neon_sf __vector__]’:
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h:169: error: cannot convert ‘float*’ to ‘float32_t*’ for argument ‘1’ to ‘void vst1q_f32(float32_t*, __builtin_neon_sf __vector__)’
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h: In function ‘void Eigen::ei_pstoreu(Scalar*, const Packet&) [with Scalar = float, Packet = __builtin_neon_sf __vector__]’:
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h:172: error: cannot convert ‘float*’ to ‘float32_t*’ for argument ‘1’ to ‘void vst1q_f32(float32_t*, __builtin_neon_sf __vector__)’
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h: In function ‘typename Eigen::ei_unpacket_traits<T>::type Eigen::ei_pfirst(const Packet&) [with Packet = __builtin_neon_sf __vector__]’:
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h:179: error: cannot convert ‘float*’ to ‘float32_t*’ for argument ‘1’ to ‘void vst1q_f32(float32_t*, __builtin_neon_sf __vector__)’
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h: In function ‘typename Eigen::ei_unpacket_traits<T>::type Eigen::ei_predux(const Packet&) [with Packet = __builtin_neon_sf __vector__]’:
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h:216: error: cannot convert ‘float*’ to ‘float32_t*’ for argument ‘1’ to ‘void vst1_f32(float32_t*, __builtin_neon_sf __vector__)’
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h: In function ‘typename Eigen::ei_unpacket_traits<T>::type Eigen::ei_predux_mul(const Packet&) [with Packet = __builtin_neon_sf __vector__]’:
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h:289: error: cannot convert ‘float*’ to ‘float32_t*’ for argument ‘1’ to ‘void vst1_f32(float32_t*, __builtin_neon_sf __vector__)’
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h: In function ‘typename Eigen::ei_unpacket_traits<T>::type Eigen::ei_predux_min(const Packet&) [with Packet = __builtin_neon_sf __vector__]’:
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h:320: error: cannot convert ‘float*’ to ‘float32_t*’ for argument ‘1’ to ‘void vst1_f32(float32_t*, __builtin_neon_sf __vector__)’
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h: In function ‘typename Eigen::ei_unpacket_traits<T>::type Eigen::ei_predux_max(const Packet&) [with Packet = __builtin_neon_sf __vector__]’:
/home/ubuntu/Documents/eigen/Eigen/src/Core/arch/NEON/PacketMath.h:348: error: cannot convert ‘float*’ to ‘float32_t*’ for argument ‘1’ to ‘void vst1_f32(float32_t*, __builtin_neon_sf __vector__)’
make: *** [main] Error 1
ubuntu@ubuntu-desktop:~/Documents/mat_mul$
我在使用 Code Sourcery 工具链时遇到的错误
ubuntu@ubuntu-desktop:~/Documents/CodeSourcery_WS/Test_Eigen$ make
/home/ubuntu/CodeSourcery/Sourcery_G++/bin/arm-none-linux-gnueabi-c++ -mfpu=neon -mfloat-abi=softfp -I /home/ubuntu/Documents/eigen/ main.cpp -o main
In file included from main.cpp:1:
/home/ubuntu/CodeSourcery/Sourcery_G++/bin/../lib/gcc/arm-none-linux-gnueabi/4.4.1/../../../../arm-none-linux-gnueabi/include/c++/4.4.1/iostream:39: fatal error: bits/c++config.h: No such file or directory
compilation terminated.
make: *** [main] Error 1
【问题讨论】:
【参考方案1】:看起来像 gcc 错误,它确实应该混合使用 float 和 float32_t 而不会出错。签出this。
编辑:这已在 CodeSourcery 工具链中修复。这是来自发行说明:
float32_t 的编译器错误。已修复一个导致 使用时的编译器错误 来自 arm_neon.h 的 float32_t 类型。
【讨论】:
您好 ognian,我已经开始使用 Code Sourcery 工具,现在我收到一个与缺少文件 c++config.h 相关的新错误。我已经用新的错误更新了我的问题,请看一下。再一次,只有当我有编译器标志 -mfpu=neon -mfloat-abi=softfp 时才会出现这些错误。没有它们,它编译得很好,没有任何问题。 那是完全不同的错误。我建议将 $CODE_SOURCERY_ROOT/arm-none-linux-gnueabi/include/c++/4.4.1/arm-none-linux-gnueabi 添加到您的包含路径中,其中 $CODE_SOURCERY_ROOT 是您安装工具链的位置以上是关于构建使用 Eigen(用于线性代数的 C++ 模板库)的项目时出现编译器错误的主要内容,如果未能解决你的问题,请参考以下文章