Eigen library for linear algebra / Teensy 3.1 / Help needed

Status
Not open for further replies.

Paraglider

Well-known member
For matrix math it would be great to be able to use the Eigen library http://eigen.tuxfamily.org on Teensy 3.1. Eigen is a C++ template library for linear algebra like matrices, vectors, numerical solvers, and related algorithms.
I found a link http://forum.arduino.cc/index.php?topic=144446.0 at the Arduino forum, post nr. 2, where someone was able to include the Eigen library and to run a sketch on an Arduino Due.

Now I would like to use the Eigen library on a Teensy 3.1, using Arduino 1.6.1 and Teensyduino 1.21, but don't know how to do that.
 
The instructions at the arduino forum seem pretty clear at first glance. Where do your problems appear? Can you be more specific?
 
There is an error compiling:

Using library Eigen313 in folder: C:\Program Files (x86)\Arduino\libraries\Eigen313 (1.0.x format)

C:\Program Files (x86)\Arduino/hardware/tools/arm/bin/arm-none-eabi-g++ -c -Os -g -Wall -ffunction-sections -fdata-sections -MMD -nostdlib -fno-exceptions -felide-constructors -std=gnu++0x -fno-rtti -mthumb -mcpu=cortex-m4 -D__MK20DX256__ -DTEENSYDUINO=121 -DARDUINO=10601 -DF_CPU=48000000 -DARDUINO_ARCH_AVR -DUSB_SERIAL -DLAYOUT_US_ENGLISH -IC:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3 -IC:\Program Files (x86)\Arduino\libraries\Eigen313 C:\Users\User\AppData\Local\Temp\build3489959118498830671.tmp\Eigen_Sample_Script.cpp -o C:\Users\User\AppData\Local\Temp\build3489959118498830671.tmp\Eigen_Sample_Script.cpp.o
In file included from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\c++\4.8.4\tuple:39:0,
from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\c++\4.8.4\functional:55,
from C:\Program Files (x86)\Arduino\libraries\Eigen313/Core:141,
from C:\Program Files (x86)\Arduino\libraries\Eigen313/Eigen313.h:35,
from Eigen_Sample_Script.ino:5:
Error compiling.
 
No actual error message? This is just the part where it is. Or does it stop with just a mere "Error Compiling"?
 
That's really odd. I've successfully used Eigen with teensyduino before and didn't have that problem. Do you have detailed logging enabled in your arduino preferences? Find them in File->Preferences.
 
Detailed logging enabled. Maybe it has something to do with Arduino 1.6.1.

Christoph, what were the versions of Eigen, teensyduino and Arduino that you have successfully used? Might it be possible to get the Eigen library that you have used together with a sample script? The sample script I use is View attachment Eigen_Sample_Script_313.ino.
 
I really don't know where I have that code and what exact versions I used, but it was about a year ago with - I think - arduino 1.0.5. I have never used arduino 1.6.x, maybe you could try 1.0.6?

You might also have a look at https://github.com/vancegroup/EigenArduino although it seems to use an older version of eigen, it should be possible to throw in a more recent version.
 
With Arduino 1.0.5 and Teensyduino 1.19 or 1.20 the error messages are as follows:

PHP:
c:/program files (x86)/arduino/hardware/tools/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/lib/thumb2\libc.a(lib_a-signalr.o): In function `_kill_r':
signalr.c:(.text+0x14): undefined reference to `_kill'
c:/program files (x86)/arduino/hardware/tools/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/lib/thumb2\libc.a(lib_a-signalr.o): In function `_getpid_r':
signalr.c:(.text+0x28): undefined reference to `_getpid'
collect2.exe: error: ld returned 1 exit status
 
No idea why this happens kill and getpid sound like 'real' os stuff, not something for a microcontroller. I can reproduce the error. With the arduino 1.6 the errors do not appear. Also the latest 3.2.4 compiles just fine.
 
Kpc, did you try with 1.6 or 1.6.1? The kill and getpid error appear with Arduino 1.0.5. With 1.6.1 the code simply does not compile. There is only the message "error compiling".
 
I use the combination of Arduino 1.6.1 with Teensyduino 1.21.
BTW, is there any way to find the teensyduino version? Either thru the GUI, or just by a file in the teensy directory? I now obtained it by checking my bash history and was lucky the wget command was still in there. (BTW I increased the bash history to a huge value, just for these kind of issues)
 
"error compiling" - without detail indication showed as a side effect in the recent IDE update and Paul did some work to clean it up - this may be another case?

Using .ino above - I pulled the code to my machine and got the same non-error error : http://forum.arduino.cc/index.php?action=dlattach;topic=144446.0;attach=45174 { I unpacked this lib into my Sketchbook\libraries }

Looking in [%appdata%\Local\Temp... :: YMMV] : C:\Users\defr\AppData\Local\Temp\console7704951434098461257.tmp

This just shows what the screen shows and the stdout.txt is empty or shows Error Compiling:
stderr.txt

In file included from i:\teensy161\hardware\tools\arm\arm-none-eabi\include\c++\4.8.4\tuple:39:0,
from i:\teensy161\hardware\tools\arm\arm-none-eabi\include\c++\4.8.4\functional:55,
from C:\tCode\libraries\Eigen313/Core:141,
from C:\tCode\libraries\Eigen313/Eigen313.h:35,
from Eigen_Sample_Script_313.ino:5:
Error compiling.
In file included from i:\teensy161\hardware\tools\arm\arm-none-eabi\include\c++\4.8.4\tuple:39:0,
from i:\teensy161\hardware\tools\arm\arm-none-eabi\include\c++\4.8.4\functional:55,
from C:\tCode\libraries\Eigen313/Core:141,
from C:\tCode\libraries\Eigen313/Eigen313.h:35,
from Eigen_Sample_Script_313.ino:5:
Error compiling.
 
Last edited:
Changed to the old version, then back to 1.6.1.
Now i suddenly get an error
Suddenly I cannot compile even an empty sketch.

Edit: Probably corrupted something. Did a fresh install. Everything works again as before.
These are the final lines of the eigen sketch:
Code:
/home/kpc/projects/teensy/arduino-1.6.1/hardware/tools/arm/bin/arm-none-eabi-objcopy -O ihex -R .eeprom /tmp/build1469436254754470396.tmp/eigen.cpp.elf /tmp/build1469436254754470396.tmp/eigen.cpp.hex 

Sketch uses 39,504 bytes (15%) of program storage space. Maximum is 262,144 bytes.
Global variables use 4,624 bytes (7%) of dynamic memory, leaving 60,912 bytes for local variables. Maximum is 65,536 bytes.

Edit: forgot to mention, I am running on linux, 64 bit
 
Last edited:
kpc, installed 1.6.1 and 1.21 on a new installed Windows 7 x64 machine. There is nothing else than arduino and teensyduino. But there is still the following error message:

Code:
In file included from C:\Program Files (x86)\Arduino\libraries\Eigen313/Eigen313.h:35:0,
                 from Eigen_Sample_Script.ino:5:
C:\Program Files (x86)\Arduino\libraries\Eigen313/Core:22:19: fatal error: complex: No such file or directory
 #include <complex>
                   ^
compilation terminated.
Error compiling.

I am stuck here. No clue what to do...
 
I am currently at my work. It might look at the STL files in /usr/include (ie the standard linux include path). However it should not.
Can you at least verify that the STL templates are part of the arduino setup. Eg by looking if the filename "complex" exists anywhere.
If it exists, then check your include serach path.
Don't know how to do that. I personally prefer Makefiles over the GUI. But then again I also prefer working with vi. Its probably just me being old-fashioned.
 
made a mistake, not selecting Teensy 3.1, instead an Arduino Uno was selected. Here are now the correct error messages for Teensy 3.1 and different versions of Arduino / Teensyduino on Windows 7 x64:

Code:
Arduino 1.6.1 and Teensyduino 1.21 / Teensy 3.1 / 48MHz / Eigen313

In file included from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\c++\4.8.4\tuple:39:0,
                 from c:\program files (x86)\arduino\hardware\tools\arm\arm-none-eabi\include\c++\4.8.4\functional:55,
                 from C:\Program Files (x86)\Arduino\libraries\Eigen313/Core:141,
                 from C:\Program Files (x86)\Arduino\libraries\Eigen313/Eigen313.h:35,
                 from Eigen_Sample_Script2.ino:5:
Error compiling.


Arduino 1.0.6 and Teensyduino 1.20 / Teensy 3.1 / 48MHz / Eigen313

c:/program files (x86)/arduino/hardware/tools/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/lib/thumb2\libc.a(lib_a-signalr.o): In function `_kill_r':
signalr.c:(.text+0x14): undefined reference to `_kill'
c:/program files (x86)/arduino/hardware/tools/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/lib/thumb2\libc.a(lib_a-signalr.o): In function `_getpid_r':
signalr.c:(.text+0x28): undefined reference to `_getpid'
collect2.exe: error: ld returned 1 exit status


Arduino 1.0.5 and Teensyduino 1.19 / Teensy 3.1 / 48MHz / Eigen313

c:/program files (x86)/arduino/hardware/tools/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/lib/thumb2\libc.a(lib_a-signalr.o): In function `_kill_r':
signalr.c:(.text+0x14): undefined reference to `_kill'
c:/program files (x86)/arduino/hardware/tools/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/4.7.2/../../../../arm-none-eabi/lib/thumb2\libc.a(lib_a-signalr.o): In function `_getpid_r':
signalr.c:(.text+0x28): undefined reference to `_getpid'
collect2.exe: error: ld returned 1 exit status
 
@paraglider: What if you compile by hand. I don't know how it works on Windows, but on linux you can enable something in the gui, that you see all compile statements scrolling by in the log part of the window. You can then copy the final g++ command before the error and paste that in a terminal.
Does it generate the same error message?

I can only get it to compile on 1.6.1. the other version, I also get the kill/getpid errors.
 
_kill and _getpid are usually called when something goes wrong - for example when an expection is thrown or when malloc can't do its job. BUT teensyduino adds compiler flags that remove exceptions, so something else is going wrong.

This might be helpful: http://stackoverflow.com/questions/...-code-with-o0-but-it-does-with-o2-dndebug-how

You can try to provide your own, here is a list of possible dummy implementations of syscalls: http://myavr.chkronline.de/html_stm32/stm32_eclipse_tut10.html

I'm not sure what flags are used in your setup, but I've had bad luck when linking with -flto (link time optimization), which either removed syscalls or seemed to create undesired duplicates.
 
This issue has come up a couple times on other libraries. You may find this hard to believe, but it's turned out to be due to improper use of vararg functions.
 
Paul: Are you saying the break in the 1.6.1 IDE producing 'meaningful' error messages is from vararg - or that the compile with this code showing up in past builds and only as "error compiling in the 1.6.1 is due to vararg?
 
I haven't looked at this code (yet). But I am saying at least 2 times before, a very similar error about _kill and _getpid turned out to be related to improper vararg usage, which happened to compile on avr-gcc, even though it's things that are absolutely wrong to do with vararg.

I have no idea if that's what's really going on here. I might dig into this soon, if it's still unresolved. But if anyone is trying now, maybe knowing improper vararg usage on other libraries showed the same errors might help? I believe one of them was EtherCard. Here's the commit that fixed the problem.

https://github.com/PaulStoffregen/EtherCard/commit/de7610f8c9b15f834b3aadba62626a82c9be1b45
 
In : "... \libraries\Eigen313\Core" at line #14 I found this cute and nearly correct note:

// first thing Eigen does: stop the compiler from committing suicide
#include "src/Core/util/DisableStupidWarnings.h"

So I commented out the include and then I got the same output up to but excluding the "error compiling" goes away - because the compile now HANGS before getting that far.

Astable compile: Oddly if I make a syntax error there or before it won't report that either. The behavior changes - but not in direct relation to the error presented.
 
Paul, is it possible to get a fix for that problem in the near future? It would be great to be able to use the Eigen library for solving complex mathematical problems on a Teensy 3.1.
 
Status
Not open for further replies.
Back
Top