Compile library examples

Hello folks,

The CLI now knows how to compile library examples.

Upgrade to the latest beta:
npm install -g https://github.com/spark/particle-cli/releases/download/v1.19.0-libraries.20/particle-cli-1.19.0-libraries.20.tgz

To compile an example in your library, open a terminal to the library directory and do:
particle compile photon examples/name_of_example

It creates a project on the fly with the example and the library source.

Let us know how it works for you!

4 Likes

Awesome :sunglasses:

KENMBP:Stepper kennethlimcp$ pcp examples/MotorKnob/

Compiling code for photon

Including:
    examples/MotorKnob/MotorKnob.ino
    library.properties
    src/Arduino.h
    src/Stepper.cpp
    src/Stepper.h
attempting to compile firmware 
downloading binary from: /v1/binaries/58548fc915db5737283909fc
saving to: photon_firmware_1481936838001.bin
Memory use: 
   text	   data	    bss	    dec	    hex	filename
   4796	      8	   1460	   6264	   1878	
Compile succeeded.
Saved firmware to: /Users/kennethlimcp/Desktop/Arduino-lib-official/Stepper/photon_firmware_1481936838001.bin

FYI, this update broke the particle flash command. I’m releasing another beta with that functionality back. too many balls in the air at the same time

npm install -g https://github.com/spark/particle-cli/releases/download/v1.19.0-libraries.20/particle-cli-1.19.0-libraries.20.tgz

2 Likes

A post was split off to new topic: Library upload broken?

@jvanier, this way to build samples seems to have issues with the default stub headers created by particle library migrate inside the src folder.

I always get

Compile failed. Exiting.
In file included from /src/libName.cpp:xx:yy:
/src/libName.h:xx:yy: fatal error: ../libName.h: No such file or directory
 #include "../libName.h"

When I remove that subfolder from src it builds fine, but I guess I might produce issues when uploading, since there ought to be a reason why migrate creates this folder and dummy headers.

I just saw this today too.

There was a change made to the API over the weekend that caused this.

I have a fix lined up and I’m working with the cloud team to roll it out ASAP.

1 Like

The fix is live now so this problem is fixed.

1 Like

@jvanier, true that error message does not pop up anymore, but no I just get a non-descriptive “Compile failed” for all of my lib examples that did build yesterday.

Is there a 1.19.2 for that?
npm update -g particle-cli doesn’t do anything for me - still only 1.19.1

The issue was server-side. CLI 1.19.1 is the latest.

I’m able to compile library examples with CLI. Can you give more details about this latest issue?

Like this?

C:\Users\Andy\Dropbox\DokumenteAndy\Particle\Libraries2.0\Adafruit_HX8357>particle compile photon examples\SpiTftBitmap

Compiling code for photon

Including:
    examples\SpiTftBitmap\SpiTftBitmap.ino
    library.properties
    src\Adafruit_HX8357.cpp
    src\Adafruit_HX8357.h
    src\Adafruit_HX8357\Adafruit_HX8357.h
attempting to compile firmware
Compile failed. Exiting.


C:\Users\Andy\Dropbox\DokumenteAndy\Particle\Libraries2.0\Adafruit_HX8357>particle compile photon examples\BreakoutTouchPaint

Compiling code for photon

Including:
    examples\BreakoutTouchPaint\BreakoutTouchPaint.ino
    library.properties
    src\Adafruit_HX8357.cpp
    src\Adafruit_HX8357.h
    src\Adafruit_HX8357\Adafruit_HX8357.h
attempting to compile firmware
Compile failed. Exiting.


C:\Users\Andy\Dropbox\DokumenteAndy\Particle\Libraries2.0\Adafruit_HX8357>particle compile photon examples\GraphicsTest

Compiling code for photon

Including:
    examples\GraphicsTest\GraphicsTest.ino
    library.properties
    src\Adafruit_HX8357.cpp
    src\Adafruit_HX8357.h
    src\Adafruit_HX8357\Adafruit_HX8357.h
attempting to compile firmware
Compile failed. Exiting.


C:\Users\Andy\Dropbox\DokumenteAndy\Particle\Libraries2.0\Adafruit_HX8357>cd ..

C:\Users\Andy\Dropbox\DokumenteAndy\Particle\Libraries2.0>cd ParticleSoftSerial

C:\Users\Andy\Dropbox\DokumenteAndy\Particle\Libraries2.0\ParticleSoftSerial>particle compile photon examples\PSS_SimpleTest

Compiling code for photon

Including:
    examples\PSS_SimpleTest\PSS_SimpleTest.ino
    library.properties
    src\ParticleSoftSerial.cpp
    src\ParticleSoftSerial.h
    src\ParticleSoftSerial\ParticleSoftSerial.h
attempting to compile firmware
Compile failed. Exiting.

The last two of these examples did build fine yesterday

The path handling got borked again on Windows. Sorry about that :bow: I’ll work on a fix.

1 Like

Now I’ve got a funny new behaviour (had something similar a while ago).
particle compile photon examples/dmy --target 0.6.1-rc.2 seems to build some other code.
Although I have got some definetly not compilable code I get this from that command

C:\Users\Particle\Libraries2.0\_todo_\uploaded\PS2Communication>particle compile photon examples/dmy --saveTo firmware.bin --target 0.6.1-rc.2

Compiling code for photon
Targeting version: 0.6.1-rc.2

Including:
    examples\dmy\dmy.ino
    library.properties
    src\PS2Communication.cpp
    src\PS2Communication.h
    src\PS2Communication\PS2Communication.h
attempting to compile firmware
downloading binary from: /v1/binaries/588b1b7fdcc9827d6858e4fd
saving to: firmware.bin
Memory use:
   text    data     bss     dec     hex filename
   4460       8    1420    5888    1700 /workspace/target/workspace.elf

Compile succeeded.
Saved firmware to: C:\Users\Particle\Libraries2.0\_todo_\uploaded\PS2Communication\firmware.bin

And not surprisingly, when building and flashing code that wouldn’t throw errors, I’d assume the build was fine and I’d scratch my head why that code is not doing what I’d expect it to do.
Pretending to build your code and downloading a rather obscure binary (which I don’t know what it actually does) isn’t a reassuring experience :wink:
However building for targets pre 0.6.1-rc.2 works as expected

This was a preprocessor issue.

I updated the version of the preprocessor for the 0.6.1-rc.2 target and this is now fixed.

1 Like

I’ll give it a try.
But the funny thing with above sketch is that it already used #pragma SPARK_NO_PREPROCESSOR so was there another preproc playing up or did the Wiring preproc still interfere despite being told not to? :confused:

The example has a .ino extension. The preprocessor is responsible for renaming the file to .cpp even if it doesn’t change the content. The issue was that the preprocessor wasn’t renaming the file :wink:

1 Like