Copyright © https://mongoose-os.com

Mongoose OS Forum

frame

How to build with a local copy of a library?

mookiedogmookiedog Washington, USA

I want to clone a local copy of a library into my own app's source tree so that I can make some test changes to the library itself. It appeared that I should use git to clone a copy into a subdirectory of a local 'deps' directory, so I did that. The issue is that none of the include files in the cloned library seem to be accessible to the other files in my build. For example, I have pulled the arduino-onewire library into my deps directory. I have a source file that tries to include "OneWire.h", which is located in deps/arduino-onewire/include. After trying about a million different things, all I ever get from the build process is:

fatal error: OneWire.h: No such file or directory

Is there something I need to do in mos.yml to explain that my library source is local instead of at github? Or was my initial theory of pulling the library into a deps directory the wrong approach?

Comments

  • mookiedogmookiedog Washington, USA

    Maybe there is a cleaner way:

    I just cloned the git repositories for the libraries that I needed into some separate directories, then copied over all the .c, .cpp, and .h files from each of those directories into my app's src directory. It is kind of ugly, but it seems to serve my purposes.

  • nliviunliviu Romania

    You just add in the libs section of your mos.yml

     - origin: <relative_or_absolute_path>/arduino-onewire
    
  • mookiedogmookiedog Washington, USA

    Relative to what path? The directory where original mos.yml is stored?

    Also, I am including the arduino OneWire library which is a library that includes its own libraries. Do I need to clone all those dependent libraries, and change all of their mos.yml files to be local?

  • mookiedogmookiedog Washington, USA

    I am having no success here. All my attempts result in errors of the general form:

    Error: reading manifest "/fwbuild-volumes/1.22.1/apps/rentalSensor/esp32/build_contexts/build_ctx_589883146/deps/arduino-dallas-temperature/mos.yml": open /fwbuild-volumes/1.22.1/apps/rentalSensor/esp32/build_contexts/build_ctx_589883146/deps/arduino-dallas-temperature/mos.yml: no such file or directory
    Error: build failed

    Is 'deps' supposed to be at the same level as the src directory, or is it supposed to be inside the src directory?

  • nliviunliviu Romania

    Here is a part of my applications/libraries tree:

    ── exterior
    │   ├── fs
    │   │   └── index.html
    │   ├── include
    │   │   ├── DS1820Handler.h
    │   │   └── MqttHandler.h
    │   ├── mos.yml
    │   └── src
    │       ├── DS1820Handler.cpp
    │       ├── MqttHandler.cpp
    │       └── main.cpp
    ├── libs
    │   ├── arduino-dallas-temperature
    │   │   ├── LICENSE
    │   │   ├── README.md
    │   │   ├── include
    │   │   │   ├── DallasTemperature.h
    │   │   │   └── mgos_arduino_dallas_temp.h
    │   │   ├── mjs_fs
    │   │   │   └── api_arduino_dallas_temp.js
    │   │   ├── mos.yml
    │   │   └── src
    │   │       ├── DallasTemperature.cpp
    │   │       ├── mgos_arduino_dallas_temp.cpp
    │   │       └── mgos_arduino_dallas_temp_c.c
    │   ├── arduino-onewire
    │   │   ├── LICENSE
    │   │   ├── README.md
    │   │   ├── include
    │   │   │   ├── OneWire.h
    │   │   │   └── mgos_arduino_onewire.h
    │   │   ├── mjs_fs
    │   │   │   └── api_arduino_onewire.js
    │   │   ├── mos.yml
    │   │   └── src
    │   │       ├── OneWire.cpp
    │   │       ├── mgos_arduino_onewire.cpp
    │   │       └── mgos_arduino_onewire_c.c
    │   ├── onewire
    │   │   ├── README.md
    │   │   ├── include
    │   │   │   └── mgos_onewire.h
    │   │   ├── mos.yml
    │   │   └── src
    │   │       └── mgos_onewire.c
    

    exterior application is using arduino-dallas-temperature, which depends of arduino-onewire, which depends of onewire.

    In exterior's mos.yml I have

      - origin: ../libs/arduino-dallas-temperature
    

    libs/arduino-dallas-temperature/mos.yml

      - origin: ../libs/arduino-onewire
    

    libs/arduino-onewire/mos.yml

      - origin: ../libs/onewire
    

    PS. I've 'git clone` arduino-dallas-temperature, arduino-onewire and onewire in the libs directory.
    PS2. I'm using mos latest.

  • mookiedogmookiedog Washington, USA

    Thanks very much. Your libs are located at the app level. Mine were inside the app. I thought that I might want to make changes to the libraries on a per-app basis. Let me see if doing it your way helps fix my stuff.

  • mookiedogmookiedog Washington, USA

    From your examples, it would appear that relative links means relative to where the original mos.yml file is located.

    I am still getting the same sorts of errors after replicating your setup:

    $ mos build --verbose --arch esp32
    Connecting to https://mongoose.cloud, user test
    Uploading sources (38907 bytes)
    Handling lib "aws"...
    Handling lib "ota-http-server"...
    Handling lib "rpc-uart"...
    Handling lib "rpc-service-ota"...
    Handling lib "ca-bundle"...
    Handling lib "wifi"...
    Handling lib "dash"...
    Handling lib "rpc-service-fs"...
    Handling lib "dht"...
    Handling lib "shadow"...
    Handling lib "ota-shadow"...
    Handling lib "ota-http-client"...
    Handling lib "rpc-service-config"...
    Handling lib "http-server"...
    Handling lib "arduino-dallas-temperature"...
    Handling lib "adc"...
    Handling lib "i2c"...
    The --lib flag was not given for it, checking repository
    The --lib flag was not given for it, checking repository
    The --lib flag was not given for it, checking repository
    The --lib flag was not given for it, checking repository
    The --lib flag was not given for it, checking repository
    The --lib flag was not given for it, checking repository
    The --lib flag was not given for it, checking repository
    The --lib flag was not given for it, checking repository
    The --lib flag was not given for it, checking repository
    The --lib flag was not given for it, checking repository
    The --lib flag was not given for it, checking repository
    The --lib flag was not given for it, checking repository
    The --lib flag was not given for it, checking repository
    The --lib flag was not given for it, checking repository
    The --lib flag was not given for it, checking repository
    Falling back to sources for "arduino-dallas-temperature" (failed to fetch prebuilt binary: unable to fetch library for swmodule of type 1)
    Prepared local dir: "/fwbuild-volumes/1.23/apps/rentalSensor/esp32/build_contexts/libs/arduino-dallas-temperature"
    The --lib flag was not given for it, checking repository
    Error: reading manifest "/fwbuild-volumes/1.23/apps/rentalSensor/esp32/build_contexts/libs/arduino-dallas-temperature/mos.yml": open /fwbuild-volumes/1.23/apps/rentalSensor/esp32/build_contexts/libs/arduino-dallas-temperature/mos.yml: no such file or directory
    The --lib flag was not given for it, checking repository
    Error: build failed

    I guess I must have not replicated your setup exactly. I git cloned the 3 libraries you mentioned. My rentalSensor app's mos.yml file contains:
    - origin: ../libs/arduino-dallas-temperature

    My arduino-dallas-temperature library's mos.yml file contains:
    - origin: ../libs/arduino-onewire

    and so on. But it seems that the build system can't even find the first link in the chain: the arduino-dallas-temperature mos.yml file.

  • nliviunliviu Romania

    I just noticed you use cloud build.
    It looks like my approach works only for local build.
    Sorry...

  • mookiedogmookiedog Washington, USA

    Do I have to do a --local build for this to work?

    I tried starting from scratch (version 1.21 mos tool install, fresh clones of the 3 libraries, updating all mos.yml files to use relative paths to the local libraries) and I still get 'file not found' errors, as below. I know I must be doing something dumb, but it is just not clear what that might be.

    `
    $ mos build --arch esp32
    Connecting to https://mongoose.cloud, user test
    Uploading sources (1882 bytes)
    Handling lib "ca-bundle"...
    Handling lib "aws"...
    Handling lib "http-server"...
    Handling lib "arduino-dallas-temperature"...
    Handling lib "dash"...
    Handling lib "ota-aws-shadow"...
    Handling lib "i2c"...
    Handling lib "ota-http-server"...
    Handling lib "ota-http-client"...
    Handling lib "rpc-uart"...
    Handling lib "rpc-service-ota"...
    Handling lib "wifi"...
    Handling lib "shadow"...
    Handling lib "dht"...
    Handling lib "rpc-service-fs"...
    The --lib flag was not given for it, checking repository
    The --lib flag was not given for it, checking repository
    The --lib flag was not given for it, checking repository
    The --lib flag was not given for it, checking repository
    Handling lib "rpc-service-config"...
    The --lib flag was not given for it, checking repository
    The --lib flag was not given for it, checking repository
    The --lib flag was not given for it, checking repository
    Handling lib "adc"...
    The --lib flag was not given for it, checking repository
    Repository "/fwbuild-volumes/1.21/apps/test/esp32/build_contexts/build_ctx_592917490/libs/adc" does not exist, cloning...

    Repository "/fwbuild-volumes/1.21/apps/test/esp32/build_contexts/build_ctx_592917490/libs/aws" does not exist, cloning...

    Repository "/fwbuild-volumes/1.21/apps/test/esp32/build_contexts/build_ctx_592917490/libs/ca-bundle" does not exist, cloning...

    Repository "/fwbuild-volumes/1.21/apps/test/esp32/build_contexts/build_ctx_592917490/libs/dht" does not exist, cloning...

    Repository "/fwbuild-volumes/1.21/apps/test/esp32/build_contexts/build_ctx_592917490/libs/dash" does not exist, cloning...

    Repository "/fwbuild-volumes/1.21/apps/test/esp32/build_contexts/build_ctx_592917490/libs/rpc-service-config" does not exist, cloning...

    Repository "/fwbuild-volumes/1.21/apps/test/esp32/build_contexts/build_ctx_592917490/libs/rpc-service-fs" does not exist, cloning...

    Repository "/fwbuild-volumes/1.21/apps/test/esp32/build_contexts/build_ctx_592917490/libs/http-server" does not exist, cloning...

    The --lib flag was not given for it, checking repository
    Falling back to sources for "arduino-dallas-temperature" (failed to fetch prebuilt binary: unable to fetch library for swmodule of type 1)
    The --lib flag was not given for it, checking repository
    Prepared local dir: "/fwbuild-volumes/1.21/apps/test/esp32/build_contexts/build_ctx_592917490/libs/arduino-dallas-temperature"
    The --lib flag was not given for it, checking repository
    Repository "/fwbuild-volumes/1.21/apps/test/esp32/build_contexts/build_ctx_592917490/libs/ota-aws-shadow" does not exist, cloning...

    The --lib flag was not given for it, checking repository
    Repository "/fwbuild-volumes/1.21/apps/test/esp32/build_contexts/build_ctx_592917490/libs/i2c" does not exist, cloning...

    Error: reading manifest "/fwbuild-volumes/1.21/apps/test/esp32/build_contexts/build_ctx_592917490/libs/arduino-dallas-temperature/mos.yml": open /fwbuild-volumes/1.21/apps/test/esp32/build_contexts/build_ctx_592917490/libs/arduino-dallas-temperature/mos.yml: no such file or directory
    The --lib flag was not given for it, checking repository
    Repository "/fwbuild-volumes/1.21/apps/test/esp32/build_contexts/build_ctx_592917490/libs/ota-http-server" does not exist, cloning...

    Error: build failed
    `

  • Do I have to do a --local build for this to work?

    Yes, remote builds can only handle libs which are publicly available at github, for local libs you have to use --local flag, and thus it requires docker to be installed on your machine.

  • mookiedogmookiedog Washington, USA

    Thanks. I'll try that next week.

Sign In or Register to comment.