Problem with include <mjs.h> into mgos library [solved]

#1

Hello
I start my first project for ModgooseOS.
This is a library that processes in C-code the response of the device received on UART. Working with UART in javascript-code.
I need to create a C structure from the device response and convert it to a javascript object.
Therefore I am using “Converting structs to objects” from the manual:

And while a build I got a error: fatal error: mjs.h: No such file or directory, although - origin: https://github.com/mongoose-os-libs/mjs is in mos.yml.

I have no ideas whi it happend, I saw into othet project using the same conversion: ds3231 and bt-common, and I can`t undestand a difference.

Here a link to github repo: https://github.com/boris-r-v/mgos-ati-uns4i
If anyone have a time to see it, and will say where is the error - I`l be happy

Thanks.

#2

Did you actually check for working examples ?
The compiler is telling you that it can’t find mjs.h. IIRC in Mongoose-OS you usually

#include "mgos_mjs.h"

which will in turn

#include "mjs.h"

for you
I don’t think that file is (nor should be) in the system include directory, the example uses double quotes instead of <>

#3

Trying to build a demo application using your library:

mgos-ati-uns4i/src/uns4i.c:1:10: fatal error: uns4i.h: No such file or directory
    1 | #include "uns4i.h"
#4

Thanks for your answers.
I undestood that gcc can`t find mjs.h, I have no ideas why.
I tryied different variants:

#include "mjs.h"

and

#include "mgos_mjs.h"

I suppose error is in project config, but I where?

#5

It looks like you are trying to build the library itself, not an application that uses it. Add it to an empty application and build it.

The build process of a library seems to be different from building an application. When building an application, mjs.h is found, while when building a library it isn’t.

When including the mjs module path to the includes section of the mjs library, mjs.h is found when building a library:

includes:
  - include
  - ${mos.modules.mjs_module.path}
#6

Thanks for the answer, yes you are right, I am building only the library
The application with it has not builded, some linking error :slight_smile: , tomorrow I will still try.

#7

Thanks everyone for the help.
As expected nliviu, when building libraries, mjs.h is not available.
Therefore, you need to use preprocessor directives:

#ifdef MGOS_HAVE_MJS
#include <mjs.h>
#endif

and wrap all your MJS dependent code in it

While build application mjs.h will be found and included in the project correctly.

Thanks again for your help, the issue has been resolved.