简体   繁体   English

Eigen 示例代码无法通过 ARM 裸机编译

[英]Eigen example code fails ARM bare-metal compile

I want to evaluate Eigen for a bare-metal ARM system.我想为裸机 ARM 系统评估Eigen Here is what I'm trying to compile:这是我要编译的内容:

#include <Eigen/Dense>
using Eigen::MatrixXd;

void test()
{
  MatrixXd m(2,2);
  m(0,0) = 3;
  m(1,0) = 2.5;
  m(0,1) = -1;
  m(1,1) = m(1,0) + m(0,1);
}

Compilation gives me this:编译给了我这个:

phil@Mint-Virtual ~/Projects/Eigen $ /usr/bin/arm-none-eabi-g++ -I ./eigen-eigen-3.3.3 test.cpp -o test.o
In file included from ./eigen-eigen-3.3.3/Eigen/Dense:1:0,
                 from test.cpp:5:
./eigen-eigen-3.3.3/Eigen/Core:66:17: fatal error: new: No such file or directory
compilation terminated.

I am a C programmer, not C++, but I do understand that this is a library problem.我是 C 程序员,而不是 C++,但我明白这是一个库问题。 I have looked at several references on using C++ on bare-metal systems, but frankly I'm still a bit puzzled about how to proceed.我已经查看了一些关于在裸机系统上使用 C++ 的参考资料,但坦率地说,我对如何进行仍然有些困惑。 I would like to just stub out the missing stuff, which seems to be malloc(), free(), and etc., so that I can get a successful compile.我只想删除丢失的东西,这似乎是 malloc()、free() 等,以便我可以成功编译。 I've tried using my own new.h with -nostdinc++ -include new.h on the compiler invocation, but that did not work.我试过在编译器调用中使用我自己的new.h-nostdinc++ -include new.h ,但这不起作用。

Am I making a simple mistake, or is trying to use Eigen in this environment a fool's errand?我犯了一个简单的错误,还是试图在这种环境中使用 Eigen 是一件傻事? Any guidance would be greatly appreciated.任何指导将不胜感激。

The bare metal system does not have a memory allocator, so new and delete cannot be used.裸机系统没有内存分配器,所以不能使用new和delete。 Code using fixed-size matrices should work:使用固定大小矩阵的代码应该可以工作:

#define EIGEN_NO_MALLOC
#include <Eigen/Dense>
using Eigen;

void test()
{
    Matrix2d m;
    m(0,0) = 3;
    m(1,0) = 2.5;
    m(0,1) = -1;
    m(1,1) = m(1,0) + m(0,1);
}

We make heavy use of Eigen C++ in our bare metal code for ARM systems.我们在 ARM 系统的裸机代码中大量使用Eigen C++ Your problem obviously is in general correlated to memory allocation not to Eigen itself.您的问题显然通常与内存分配相关,而不是与 Eigen 本身相关。 You can however implement this in a basic form to use most of fixed-size allocated C++ constructs with some simple mockup of new und delete .但是,您可以以基本形式实现这一点,以使用大多数固定大小分配的 C++ 构造以及一些简单的newdelete模型。 We used a construct like the following:我们使用了如下结构:

extern"C"
void *malloc(size_t){
    return (void*)(0);
}

extern"C"
void free(void*){};


// C++ mini-definition of new & delete and aeabi_atexit:
void* operator new(size_t size, const std::nothrow_t& nothrow_value)throw(){
    return malloc(size);
}

void* operator new(size_t size) {
    return malloc(size);
}

void operator delete(void* p) throw(){
    free(p);
}


extern"C"
int __aeabi_atexit(void*,void(*)(void*),void*){
    return 0;
}

Other resources You might consider:其他资源您可能会考虑:

I would have posted more resources, but my account only allows two of them...我本来可以发布更多资源,但我的帐户只允许其中两个...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM