Copyright © https://mongoose-os.com

Mongoose OS Forum

frame
ATTENTION! This forum has moved to:

https://community.mongoose-os.com

Do not post any new messages.

Referencing My Libs libraries

fitandstrongfitandstrong Franklin Park, IL

I'm working on an app to make use of a separate library to handle comm with an accelerometer. I've got a main.cpp in My Apps, but I can't seem to figure out how to include my new library code which exists in My Libs into the My Apps app. What am I missing? I've used lots of prefixes for the file mma8451.h include line, plus no prefix, and I've tried to add it to the mos.yml file. No luck on any of the ideas/experiments so far, so I clearly am missing a simple part of this somehow. Any help would be appreciated. I would like to clean this up, test it, and then as long as it works, offer it up for use by everyone else. Note that this is all new code, so my app is untested and in the long run, I am going to make the app and library part of my product, so having them local to me even if I contribute the library to github makes sense for my implementation. Thanks.

#include "fw/src/mgos.h"
#include "fw/src/mgos_i2c.h"
#include "fw/src/mgos_config.h"
#include "libs/mma8451.h"

MMA8451 *mma8451;

results in

src/main.cpp:4:26: fatal error: libs/mma8451.h: No such file or directory
 #include "libs/mma8451.h"

Comments

  • SergeySergey Dublin, Ireland

    Please take a look at https://mongoose-os.com/docs/core_components/apps.html#how-to-create-a-new-library
    Let me know if that is unclear, I'll update.

  • fitandstrongfitandstrong Franklin Park, IL
    edited June 2017

    Thank you, but I still seem to be confused. I missed the origin: part, but had the rest. It still doesn't work. Probably a naming issue. Here is what I have so far. It's a cpp class in a .cpp and .h file under .mos/libs/mma8451/src with the names mgos_mma8451.cpp and mgos_mma8451.h.

    I get the following when I hit compile.

    Build failed:stat mgos_mma8451: no such file or directory
    

    my libs section of mos.yml for my app

    libs:
        # common mgos libs
      - origin: https://github.com/mongoose-os-libs/rpc-loopback
      - origin: https://github.com/mongoose-os-libs/rpc-mqtt
      - origin: https://github.com/mongoose-os-libs/rpc-service-config
      - origin: https://github.com/mongoose-os-libs/rpc-service-fs
      - origin: https://github.com/mongoose-os-libs/rpc-service-gpio
      - origin: https://github.com/mongoose-os-libs/rpc-service-i2c
      - origin: https://github.com/mongoose-os-libs/rpc-service-ota
      - origin: https://github.com/mongoose-os-libs/rpc-uart
      - origin: mgos_mma8451
    

    My header contains

    #ifndef _MMA8451_H_
    #define _MMA8451_H_
    
    #include "src/fw/mgos.h"
    #include "src/fw/mgos_i2c.h"
    #include "stdbool.h"
    
    #ifdef __cplusplus
    extern "C" {
    #endif
    
    // Required definition
    bool mgos_mma8451_init(void);
    
    #ifdef __cplusplus
    }
    #endif
    

    And the cpp file includes the mgos_mma8451_init() function with a return value. I can duplicate what some of the other libs do, by putting the init function in a .c file instead, but I don't see why that would make a difference.

    EDIT
    I think the mos.yml origin is a path reference, so I updated it to be just mma8451 to match what is in .mos/libs, but the only change there was that it now says this

    Build failed:stat mma8451: no such file or directory
    
  • Hello,

    I have a similar (same?) issue:

    libs:
      - origin: https://github.com/mongoose-os-libs/mjs
      - origin: https://github.com/mongoose-os-libs/ota-http-server
      - origin: https://github.com/mongoose-os-libs/rpc-loopback
      - origin: https://github.com/mongoose-os-libs/rpc-mqtt
      - origin: https://github.com/mongoose-os-libs/rpc-service-config
      - origin: https://github.com/mongoose-os-libs/rpc-service-fs
      - origin: https://github.com/mongoose-os-libs/rpc-service-gpio
      - origin: https://github.com/mongoose-os-libs/rpc-service-i2c
      - origin: https://github.com/mongoose-os-libs/rpc-service-ota
      - origin: https://github.com/mongoose-os-libs/rpc-uart
      - origin: https://github.com/mongoose-os-libs/arduino-adafruit-ssd1306

    works fine.

    I checked my ~.mos/libs All libraries were there.

    Now I changed:
    - origin: arduino-adafruit-ssd1306

    I expected, that the compiler uses this local lib and everthings works..
    The following happens:

    ...
    Clean, skipping (will be handled remotely)
    Handling lib "rpc-uart"...
    The --lib flag was not given for it, checking repository
    Clean, skipping (will be handled remotely)
    Handling lib "arduino-adafruit-ssd1306"...
    The --lib flag was not given for it, checking repository
    Error: stat arduino-adafruit-ssd1306: no such file or directory
  • SergeySergey Dublin, Ireland

    Run mos --v 4 --logtostderr ..... please, post the logs

  • Here is mine:
    see file.

  • For local files, should we be using - name: arduino-adafruit-ssd1306

    Although, I get an error on unrecognized "Arduino.h" when I try to compile

  • fitandstrongfitandstrong Franklin Park, IL

    Sorry, I was out of the office for a little bit. Here is the logs requested last week. Same issue today.

Sign In or Register to comment.