Nu such file or directory when using a library with subfolders

Hello,

I want to incorporate the GitHub - mzinin/s2e2.cpp: C++ implementation of Simple String Expression Evaluator library library into my project.

Since I cannot use git, I have downloaded the library manually into the 'lib/s2e2cpp' folder of my project.

The folder structure of my project on my Linux environment now looks like this:


...
lib/s2e2cpp/
├── include
│   └── s2e2
        ...
│       ├── evaluator.hpp
│       ├── function.hpp
│       ├── functions
│       │   ├── function_add_days.hpp
            ...
│       │   └── function_replace.hpp
│       ├── operator.hpp
│       └── operators
│           ├── operator_and.hpp
            ...
│           └── operator_plus.hpp
└── src
    ├── evaluator.cpp
    ...
    ├── functions
        ...
    │   └── function_replace.cpp
    ├── operators
    │   ├── operator_and.cpp
        ...
    │   ├── operator_plus.cpp
    │   └── priorities.hpp
    ...
    └── utils.hpp
src/
   ...

platformio.ini

In my main source file I’m including the lib and declaring an s2e2::Evaluator object:

#include <s2e2/evaluator.hpp>
s2e2::Evaluator MyEvaluator;

But when I try to build the project, I’m getting a “no such file or directory error” for the ‘functions.hpp’ file, which is linked from the ‘evaluator.hpp’ file:

in file included from src/main.cpp:129:
lib/s2e2cpp/include/s2e2/evaluator.hpp:3:10: fatal error: s2e2/function.hpp: No such file or directory
    3 | #include <s2e2/function.hpp>
      |          ^~~~~~~~~~~~~~~~~~~

The lib_ldf_mode in my platformio.ini is set to deep+

I also tried

  • adding the library’s relevant paths via -I switches in the build_flags
  • adding the library’s relevant paths to the ‘lib_extra_dirs’ flag
    however I’m not getting passed this error.

It looks to me like this is related to the use of subfolders in the library, but I’m not sure how to force traversing through these subfolders.

Finally I tried to add a ‘library.json’ to the root folder of this library. After that, I’m getting the same error, but this time for the file in the include directive, namely “evaluator.hpp”

I might have made a mistake in the composition of this library.json, altough, the pio pkg pack command seems to accept the library.json file

Thanks!

Regarding to the readme GitHub - mzinin/s2e2.cpp: C++ implementation of Simple String Expression Evaluator library your include directive is wrong.

#include <s2e2/evaluator.hpp>

s2e2::Evaluator evaluator;

evaluator.addStandardFunctions();
evaluator.addStandardOperators();

const std::string expression = "A + B";
const auto result = evaluator.evaluate(expression);

You are absolutely correct sivar2311.

However, it was a typo I made during the writing of this post.; I am actually using the correct include #include <s2e2/evaluator.hpp>. I’ve corrected it it in my original post.

Thanks for thinking along!

If you add a minimal library.json to the /lib/s2e2 folder it should work without errors. At least it compiles without errors for me.

library.json:

{
    "name": "s2e2",
    "version": "0.1.0"
}

Sidenote:
This is done automatically if git is available and the library is included using lib_deps:
lib_deps = https://github.com/mzinin/s2e2.cpp

Thanks again for your assistance sivar2311.
I tried with your example library.json file but the error remains:

src/main.cpp:129:12: fatal error: **s2e2/evaluator.hpp**: No such file or directory
  129 |   **#include <s2e2/evaluator.hpp>**
      |            ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
*** [.pio/build/RPI4/src/main.o] Error 1

As for you sidenote: Thank for the tip. I am aware of the benefits of cloning via github, however in this case that is not an option as I’m restricted by policies (backed by a very efficient firewall :slight_smile: )

I’ve set up a test project.
You’ll find the source here: GitHub - sivar2311/s2e2-pio-demo

It compiles fine, without any issues.

Steps I made:

  • created PIO project folder
  • downloaded the s2e2 sourcecode as zip and put the content to ./lib/s2e2cpp
  • added a minimum library.json to ./lib/s2e2cpp
  • wrote a simple main.cpp for test compile

Note: I don’t have RPI4 so i used the native platform for test-compile.

As for you sidenote: Thank for the tip. I am aware of the benefits of cloning via github, however in this case that is not an option as I’m restricted by policies (backed by a very efficient firewall :slight_smile: )

That’s what I thought. I just wanted to point out what happens automatically in the background when using lib_deps in conjunction with a GitHub repository.

Very kind of you sivar2311. That was the next thing on my list, but you prepared it very nicely for me :pray: I only changed the platform to linux_arm

And more or less as expected, it compiles perfectly fine on the same development environment…

I’m running out of ideas where to look. I reviewed the verbose log output, but didn’t notice anything out of the ordinary. Maybe worth mentioning is that the intellisense works fine, I can ctrl-click to jump to the class definition. Any suggestions welcome!

And more or less as expected, it compiles perfectly fine on the same development environment…

If it now compiles without errors, what is the problem?

No, I expressed wrong. I meant your sample compiles without issues. The original project still gives the same ‘no such file’ error.

I literally moved the s2e2cpp folder from your testproject to my own project’s lib folder, and even then my own project keeps produces the ‘no such file’ error.

Ok, understood :sweat_smile:
The error message should show where exactly the error happened.

Can you share your project somewhere?

Sharing the project is not an option, unfortunately.

I can provide whatever information you need.

Right now I’m testing by moving parts of my project into your demo project and hopefully at some point I’ll run into the same error. A cumbersome work because there are dozens of libraries (static and dynamically linked) but I see no other option. I’ll keep you informed! Meanwhile, thanks for your efforts!!

1 Like