Multiple header files in a single library

I am using this toolkit called ACADO to create an MPC for my project. This toolkit is written in C++ and has the associated header and cpp files. So I uploaded the folder containing all the files into the libraries folder in arduino. To use the toolkit in a script, I have to write

#include “acado_toolkit.hpp”

However, inside this hpp file, it contains references to other hpp files, as shown in the picture attached. These header files are in the same folder within arduino/libraries. When I try to compile the script that I wrote, I get the message (as an example):

fatal error: acado_optimal_control.hpp: No such file or directory

So for some reason the compiler does not recognize the other header files inside that folder. There are many (50+) of these header files inside the folder, and I don’t want to make a separate folder within arduino/libraries for each of them. Is there any simple solution to this? Thanks in advance!

Can you post a link to where you downloaded the library from so I can test it out on my computer?

The download procedure is a bit involved, but the link is here:

http://acado.github.io/install_windows.html

Ewww. Please zip your library folder and add it as an attachment in a reply here. If you click the "Reply" button, you'll seen an "Attachments and other settings" button that will allow you to make the attachment.

No problem. It’s attached below

acado_library.zip (961 KB)

josh_pili:
fatal error: acado_optimal_control.hpp: No such file or directory

I don't get this error. It makes me think maybe something is wrong with your library installation.

However, I do get a lot of similar errors:

E:\arduino\libraries\acado_library/acado_integrators.hpp:35:39: fatal error: acado/utils/acado_utils.hpp: No such file or directory

The reason for these is that the #include directives of the library are written with the expectation that the library is structured in to subfolders, but your library has all the files dumped directly in the root of the library folder. In order to fix the error above, you need to move acado_utils.hpp to the acado/utils subfolder of the library. There are many more of this type of issue. It would likely be best to spend a little time seeing if you can figure out what happened to those folders, instead of spending forever manually generating the correct folder structure.

I understand. That’s what I was thinking too. So I’ve done just that, but I still get the same error as you mentioned right now. Check out the updated library attached here, and see if I’m still doing something wrong. Thanks!

acado_library.zip (1.58 MB)

Create a subfolder named acado and move all the subfolders of the library under that folder:

libraries
|_acado
|_acado_code_generation.hpp
|_etc.
|_acado
|_bindings
|_etc.

After that, I get this error:

E:\arduino\libraries\acado/acado/matrix_vector/matrix_vector_tools.hpp:39:48: fatal error: external_packages/eigen3/Eigen/Dense: No such file or directory

and indeed, that file doesn't exist. Maybe the documentation tells you where to get it from, or it is procured during the build process.

Ok, I got the external_packages folder. But when I put it in \libraries\acado/acado, I still get that same error message. Where do I need to put this folder then? Sorry for all the questions, you've been extremely helpful

I put the external_packages folder inside the original \libraries\acado directory. However, now I’m just getting a big mess… I don’t think the Arduino IDE is compatible with these libraries. Here’s my error message:

Arduino: 1.8.7 (Windows 10), TD: 1.46, Board: "Teensy 3.2 / 3.1, Serial, 96 MHz (overclock), Faster, US English"

In file included from C:\Users\jpili\OneDrive\Documents\Arduino\libraries\acado/acado/utils/acado_utils.hpp:42:0,

                 from C:\Users\jpili\OneDrive\Documents\Arduino\libraries\acado/acado_integrators.hpp:35,

                 from C:\Users\jpili\OneDrive\Documents\Arduino\libraries\acado/acado_optimal_control.hpp:35,

                 from C:\Users\jpili\OneDrive\Documents\Arduino\libraries\acado/acado_toolkit.hpp:35,

                 from C:\Users\jpili\OneDrive\Documents\Arduino\NMPC\NMPC.ino:1:

C:\Users\jpili\OneDrive\Documents\Arduino\libraries\acado/acado/utils/acado_constants.hpp:62:1: warning: floating constant truncated to zero [-Woverflow]

 const double ZERO = 1.0e-50;

 ^

In file included from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/wiring.h:38:0,

                 from C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/WProgram.h:45,

                 from C:\Users\jpili\AppData\Local\Temp\arduino_build_256697\pch\Arduino.h:6:

C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/core_pins.h:38:14: error: expected identifier before numeric constant

 #define LOW  0

              ^

C:\Users\jpili\OneDrive\Documents\Arduino\libraries\acado/acado/utils/acado_types.hpp:295:5: note: in expansion of macro 'LOW'

     LOW,         /**< Print error messages only.                                         */

     ^

C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/core_pins.h:38:14: error: expected '}' before numeric constant

 #define LOW  0

              ^

C:\Users\jpili\OneDrive\Documents\Arduino\libraries\acado/acado/utils/acado_types.hpp:295:5: note: in expansion of macro 'LOW'

     LOW,         /**< Print error messages only.                                         */

     ^

C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/core_pins.h:38:14: error: expected unqualified-id before numeric constant

 #define LOW  0

              ^

C:\Users\jpili\OneDrive\Documents\Arduino\libraries\acado/acado/utils/acado_types.hpp:295:5: note: in expansion of macro 'LOW'

     LOW,         /**< Print error messages only.                                         */

     ^

C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/core_pins.h:1948:25: error: expected identifier before numeric constant

 #define EXTERNAL        0

                         ^

C:\Users\jpili\OneDrive\Documents\Arduino\libraries\acado/acado/utils/acado_types.hpp:817:2: note: in expansion of macro 'EXTERNAL'

  EXTERNAL,  /**< External, performed within a QP solver. */

  ^

C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/core_pins.h:1948:25: error: expected '}' before numeric constant

 #define EXTERNAL        0

                         ^

C:\Users\jpili\OneDrive\Documents\Arduino\libraries\acado/acado/utils/acado_types.hpp:817:2: note: in expansion of macro 'EXTERNAL'

  EXTERNAL,  /**< External, performed within a QP solver. */

  ^

C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/core_pins.h:1948:25: error: expected unqualified-id before numeric constant

 #define EXTERNAL        0

                         ^

C:\Users\jpili\OneDrive\Documents\Arduino\libraries\acado/acado/utils/acado_types.hpp:817:2: note: in expansion of macro 'EXTERNAL'

  EXTERNAL,  /**< External, performed within a QP solver. */

  ^

In file included from C:\Users\jpili\OneDrive\Documents\Arduino\libraries\acado/acado/utils/acado_utils.hpp:41:0,

                 from C:\Users\jpili\OneDrive\Documents\Arduino\libraries\acado/acado_integrators.hpp:35,

                 from C:\Users\jpili\OneDrive\Documents\Arduino\libraries\acado/acado_optimal_control.hpp:35,

                 from C:\Users\jpili\OneDrive\Documents\Arduino\libraries\acado/acado_toolkit.hpp:35,

                 from C:\Users\jpili\OneDrive\Documents\Arduino\NMPC\NMPC.ino:1:

C:\Users\jpili\OneDrive\Documents\Arduino\libraries\acado/acado/utils/acado_types.hpp:820:1: error: expected declaration before '}' token

 };

 ^

Error compiling for board Teensy 3.2 / 3.1.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

There used to be issues with OneDrive; not sure if they were fixed in IDE 1.8.7 (or fixed in later versions or not yet fixed).

I have very much my doubts that this library was ever written with the Arduino environment in mind. So it will be a lot of trying to get it t work.

The problem is that there are some name conflicts between the acado library and the Arduino core library. For example, in C:\Users\jpili\OneDrive\Documents\Arduino\libraries\acado/acado/utils/acado_types.hpp you have this code:

enum PrintLevel
{
    NONE,        /**< No output.                                                         */
    LOW,         /**< Print error messages only.                                         */
    MEDIUM,      /**< Print error and warning messages as well as concise info messages. */
    HIGH,        /**< Print all messages with full details.                              */
    DEBUG        /**< Print all messages with full details as well                       *
                     *   all ugly messages that might be helpful for                        *
                     *   debugging the code.                                                */
};

Then in C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3/core_pins.h you have this code:

#define LOW  0

Two completely different uses of the name LOW. The solution is to change the LOW name in the acado library to a unique name (something like ACADO_LOW) to fix the conflict. You should be able to do it without too much difficulty using a text editor that does search and replace over a folder. I know Notepad++ can do this. The author of any library specifically written for Arduino would know that LOW was off limits.

sterretje:
There used to be issues with OneDrive; not sure if they were fixed in IDE 1.8.7 (or fixed in later versions or not yet fixed).

That issue was fixed in Arduino IDE 1.8.6, so not a problem here. That issue actually just came up in a different thread today. It used to be such a common issue, but then it hasn’t come up here for so long that it felt like seeing my old friend “readlink” again.

sterretje:
I have very much my doubts that this library was ever written with the Arduino environment in mind. So it will be a lot of trying to get it t work.

I think it’s certain it wasn’t written for Arduino. There are no indications so far that it can’t be made to work for Arduino, but there is certainly that possibility. I haven’t looked at the code or documentation for clues.