Compiling and including external library source

I am wondering if someone could help me compile and include external library into my application. I’ve looked at the docs, but haven’t had any luck yet.

As some background, I am working on a product, and would like to share libraries across multiple applications, such as factory test app, manufacturing, board bringup, etc. I am compiling everything locally so I can make modifications to particle firmware code, and would like to keep all libraries on my local machine.

My folder structure is the following:

top_dir
 apps
 - test_project
 -- firmware
 --- test_project.cpp
 lib
 - test_lib
 -- test_lib
 --- test_lib.cpp
 --- test_lib.h
 submodules
 - particle_firmware 

I would like to include test_lib.h in my test_project.cpp app. I’m compiling from the top directory with the command: ./po electron build apps/$APP_TO_BUILD where ./po is the po-util executable

If it helps, I’m using a modified version of po-util. I’m able to compile successfully without trying to include test.h into my program, but when compiling with #include “test.h” in my program, I get an error. I’ve tried the instructions at https://github.com/spark/firmware/blob/develop/docs/build.md#external_libs but still haven’t had any luck.

Any help figuring this out would be much appreciated!

Thank you

1 Like

I could assist with CLI compiling and native local toolchain but po-util is @nrobinson2000’s project.

3 Likes

Hi @lbruder827,

Have you tried using the structure I designed specifically for po-util?

You can create a project using:

po electron init <PROJECT_NAME>`

Also, I’d recommend trying po-util’s built-in library manager.

The quickest way to use test_lib with your project would be to run po lib and then copy the test_lib directory with the .cpp and .h inside to ~/.po-util/lib

Then, in your project you could do:

$ po lib add test_lib

Using po-util it was designed to be used, your projects (“apps”) would be created in top_dir like this:

top_dir/
- test_project/
-- firmware/
--- main.cpp
-- ....
- test_project1/
-- firmware/
--- main.cpp
-- ....

Your test_lib library would be in ~/.po-util/lib like this:

~/.po-util/lib/
- test_lib/
-- test_lib.cpp
-- test_lib.h
- ....

How have you modified po-util?

1 Like

Thank you, I just got this working, but had to repoint some of the things to my local repo and make a few modifications to do relative symlinks instead of absolute since multiple people will be contributing to my repo. Here is my updated po-util https://pastebin.com/NbP2jBet.

2 Likes

Great! Thanks for using po-util.

1 Like

I really appreciate the work you put into it! It’s working very well!

2 Likes

Great work!

Interesting Modifications…

If I were you I’d create a fork of po-util on GitHub so others could use your changes and so you could pull in any new changes I make.