However, when I build the PX4 Autopilot code with “make px4_fmu-v6c_default”, I get below error:
/home/conley/UAV/14.3/PX4-Autopilot/src/lib/Eigen/Core:50:10: fatal error: complex: No such file or directory
50 | #include <complex>
| ^~~~~~~~~
Through research, it was found that the issue was caused by not linking the C++ standard library during compilation. How can the standard library be added? or are there other ways to resolve this issue?
I have worked around the same problem with the TFLM library, you can see how I’ve solved it (very hacky solution) in the CMakeLists.txt files of this PR:
You also have to make sure to exclude tests, I had this problem with TFLM, and I know another who have used Eigen for other hardware who had problems with tests there as well
In ‘lib/CMakeLists.txt’, add ‘add_subdirectory(tflm EXCLUDE_FROM_ALL)’
Finally, in ‘src/modules/mc_nn_control/mc_nn_control.hpp’, it can be directly referenced.
Is my understanding correct, or are there any necessary steps missing?
Currently, I have doubt about this solution:
Is it sufficient to just perform step 2 in ‘tflm/CMakeLists.txt’, or is it necessary to download the C++ standard library as well?
I understand your doubts, I’m very inexperienced with CMakeLists etc, but this works at least. I’ve tried several days to make a better solution, but I’ve not been able to.
Yes you have to download it, when I build TFLM by itself it downloads GCC 13.2.1 which is what I use. There is a flag in the Nuttx builds (-nostdinc++) that stops you from including standard c++ libraries, so therefore I copied the c++ standard headers out of the gcc folder into a separate include folder to circumvent til flag. If you remove the flag the normal build fails so I would reccomend not doing that, but if you want to try the line is found at platforms/nuttx/cmake/px4_impl_os.cmake at line 74.
In my case I also need C++ version 17, so in the main /CMakeLists.txt I changed that in line 270.
I also changed the toolchain in platforms/nuttx/cmake/Toolchain-arm-none-eabi.cmake
You also need to reference the library in the CMakeLists.txt of the module so src/modules/mc_nn_control/CMakeLists.txt
If you find a better solution please reach out to me, as I would love to impove my PR as well! And if you get Eigen to work at all I would love for you to tell me that as well so I can compare Eigen vs TFLM for inference in my master thesis
Thank you very much for your reply again.
I will follow your advice to integrate the Eigen library with PX4 firmware. If I get any results, I will contact you at the first opportunity.