tttapa / Linear-Algebra

Educational linear algebra algorithms
https://tttapa.github.io/Linear-Algebra
GNU General Public License v3.0
9 stars 2 forks source link

Problems compiling for ESP32 #1

Open MatthewFehl365 opened 2 years ago

MatthewFehl365 commented 2 years ago

Hello,

I'm trying to impliment this branch on the ESP32 but I've ran into some issues.

Code:

include "C:\Users\mxf5351\Documents\Linear-Algebra-arduino\Linear-Algebra-arduino\src\Linear_Algebra.h"

include "C:\Users\mxf5351\Documents\Linear-Algebra-arduino\Linear-Algebra-arduino\src\include\linalg\HouseholderQR.hpp"

include "C:\Users\mxf5351\Documents\Linear-Algebra-arduino\Linear-Algebra-arduino\src\include\linalg\Matrix.hpp"

void setup(){ Matrix A = { {11, 12, 13}, {21, 22, 23}, {31, 32, 33}, }; } void loop() {}

Errors: sketch\sketch_aug06a.ino.cpp.o:(.literal._ZNK6Matrix7printToER5Print[Matrix::printTo(Print&) const]+0x0): undefined reference to Matrix::print(Print&, unsigned char, unsigned char) const' sketch\sketch_aug06a.ino.cpp.o:(.literal._Z5setupv+0x4): undefined reference toSquareMatrix::SquareMatrix(std::initializer_list<std::initializer_list >)' sketch\sketch_aug06a.ino.cpp.o: In function Matrix::printTo(Print&) const': C:\Users\mxf5351\Documents\Linear-Algebra-arduino\Linear-Algebra-arduino\src\include/linalg/Matrix.hpp:260: undefined reference toMatrix::print(Print&, unsigned char, unsigned char) const' sketch\sketch_aug06a.ino.cpp.o: In function setup()': C:\Users\mxf5351\Documents\sketch_aug06a/sketch_aug06a.ino:10: undefined reference toSquareMatrix::SquareMatrix(std::initializer_list<std::initializer_list >)' collect2.exe: error: ld returned 1 exit status exit status 1 Error compiling for board DOIT ESP32 DEVKIT V1.

I'm stumped as to why this is occurring as these functions are absolutely defined in the library.

Any thoughts or suggestions would be greatly appriciated.

tttapa commented 2 years ago

#include "C:\Users\mxf5351\Documents\Linear-Algebra-arduino\Linear-Algebra-arduino\src\Linear_Algebra.h"

It's never a good idea to include headers using an absolute path.

Try installing the library using the Sketch > Include Library > Add .ZIP Library menu in the Arduino IDE, and then include the relative path, e.g. #include <Linear_Algebra.h>. If the library is not installed and included properly, the IDE will not link to it, resulting in the undefined reference errors you're seeing.

MatthewFehl365 commented 2 years ago

Thank you for the help, I managed to get it to work after installing the library correctly but I also need to change the function in householdQR.cpp ComputeFactorization to not use std::copysign. I had to include the cmath header and remove the std:: namespace. Might be a small bug when compiling on ESP32 or it might be just my system.

tttapa commented 2 years ago

remove the std:: namespace

That's not a good idea, the compiler will not select the right overload of these C math functions, you have to use the C++ math functions prefixed with std::.

The latest CI run was successful for ESP32, so I'm not sure why you're seeing this error: https://github.com/tttapa/Linear-Algebra/runs/1942413800?check_suite_focus=true
It was a while ago, maybe there's a problem with a newer version of the ESP32 Arduino Core, I'll look into that on Monday.

MatthewFehl365 commented 2 years ago

Sounds good. Only the copysign function was throwing an error saying "std::copysign" is not a member of the std namespace.

tttapa commented 2 years ago

The examples compile successfully for me using Arduino 1.8.15 and ESP32 core version 1.0.6.