Shared library for all apps

  1. My goal is: Create a shared library among apps
  2. My actions are: In the root at the same level as mos.exe, a folder for the library mylib created with *.c and *.h inside. In my app’s mos.yml, a reference added to the new library:

libs:
- name: mylib

I also add new sources with

sources:
- src
- ./mylib

  1. The result I see is: An error with no such file or directory. The screen capture is shown below.
  2. My expectation & question is: The user guide states that we should create a new library in the app under /deps but it will lose sharing ability that only the particular app can use the new library. Now I need to create a library that can be shared among apps. How to do it?

You have 2 options:

cloud build: create your library in the current application’s deps directory. Test it, upload it to github. After that you will be able to include it in any application

  - origin: https://github.com/<account>/<lib_name>

local build: create your library in a directory of your choice. Include it in any application

  - origin: <path>/<lib_name>

I am building it for local. Tried several ways but still the application build with error.

origin: ./mylib

Even tried

origin: c:/mos/mylib

All attempts do not build.

What are the error messages when you run mos build --local --platform esp32?

I have Error: open C:\mos\app2\mylib\mos.yml: The system cannot find the path specified.

Directory structure is like:
folder_struct

In mos.yml of the app, I have

sources:
- src
- ./mylib
#...
libs:
  - origin: https://github.com/mongoose-os-libs/boards
  - origin: https://github.com/mongoose-os-libs/ca-bundle
  - 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-uart
  - origin: https://github.com/mongoose-os-libs/wifi
  - origin: https://github.com/mongoose-os-libs/dht
  - name: other_lib
  - origin: ./mylib

From the error, it seems mylib is not treated as a directory in the root.

Remove ./mylib from the sources section.
Remove - name: other_lib, replace - origin: ./mylib with - origin: ../mylib and rebuild.

To avoid stupid mistakes, I restarted everything with template clone from github with command:
mos clone https://github.com/mongoose-os-apps/empty app1
In mos.yml of app1 in the root, I just added origin: ../mylib. Now, the app’s mos.yml is like:

author: mongoose-os
description: A Mongoose OS app skeleton
version: 1.0
libs_version: ${mos.version}
modules_version: ${mos.version}
mongoose_os_version: ${mos.version}

tags:
  - c
sources:
  - src
filesystem:
  - fs
libs:
  - origin: https://github.com/mongoose-os-libs/boards
  - origin: https://github.com/mongoose-os-libs/ca-bundle
  - 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-uart
  - origin: ../mylib

Now, app2 is irrelevant. The directory structure looks like:

C:/mos
      /app1
      /app2
      /mylib
         |--/include
         |--/src
         |--mos.yml
      mos.exe

mylib’s mos.yml is very simple with listing as shown below:

author: John
type: lib
description: myLib
version: 1.0
platforms: [esp32]

sources:
  - src

includes:
  - include

filesystem:
  
config_schema:
  
tags:
  - c
  - docs:drivers:mylib

manifest_version: 2017-09-29

A mos build returns the error:
Error: open /data/fwbuild-volumes/2.17.0/apps/app1/esp32/build_contexts/mylib/mos.yml: no such file or directory

Screen capture is shown here:

This setup will work only for local builds, i.e. mos build --local which needs Docker to be installed on your computer.
Local and remote builds

If remote build is allowed, does it restrict to using https://github.com/mongoose-os-libs/...?
I have tried to create a repo with my github account like https://github.com/my_repo/mongoose-os-libs, in mos.yml I changed it to:

libs:
  - origin: https://github.com/mongoose-os-libs/boards
  - origin: https://github.com/mongoose-os-libs/ca-bundle
  - 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-uart
  - origin: https://github.com/my_repo/mongoose-os-libs

mos build returns an error :

undefined reference to `mgos_mongoose_os_libs_init`

How to create a new library

Here is how I add two of my libraries hosted on github

  - origin: https://github.com/nliviu/sdlib
  - origin: https://github.com/nliviu/board-led
1 Like

Thank you nliviu. It works with a public repo but it forces into open-source. Anyway, the new, shared library works.

You can subscribe for a pro account and make your repos private.

Or install docker and keep your libs on your computer.

Private repo works for free account now. I tried a private repo but it didn’t compile. The same code compiled OK after switching private to public repo.

I am afraid installing one more component (docker) will create more issues.