mirror of
https://github.com/kakopappa/how-to-make-a-precompiled-arduino-library-for-esp8266-esp32.git
synced 2025-06-07 21:50:13 +03:00
initial commit
This commit is contained in:
commit
f30d70cdaf
52
ReadMe.md
Normal file
52
ReadMe.md
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
Step 1:
|
||||||
|
|
||||||
|
Create hello.cpp and hello.h and add the implementation.
|
||||||
|
|
||||||
|
Example files are in lib folder.
|
||||||
|
|
||||||
|
Step 2:
|
||||||
|
|
||||||
|
Make the archive file (.a) using xtensa-esp32-elf-gcc.exe for ESP32 and use xtensa-lx106-elf-gcc for ESP8266
|
||||||
|
|
||||||
|
xtensa-esp32-elf-gcc.exe -c hello.cpp -o libhello.o
|
||||||
|
xtensa-esp32-elf-ar.exe crf libhello.a libhello.o
|
||||||
|
|
||||||
|
Note: xtensa-esp32-elf-gcc.exe is located here if you have installed ESP32 in your arduino IDE.
|
||||||
|
You may want to add this path to system env for easy access.
|
||||||
|
C:\Users\<USERNAME>\AppData\Local\Arduino15\packages\esp32\tools\xtensa-esp32s2-elf-gcc\gcc8_4_0-esp-2021r2-patch3\bin\
|
||||||
|
|
||||||
|
Now you should have a libhello.a in the path.
|
||||||
|
|
||||||
|
Step 3:
|
||||||
|
1. Make the library for Ardunio (arduino-helloworld-lib) and copy the header files (lib\hello.h) to library src folder (arduino-helloworld-lib\src).
|
||||||
|
2. Copy the libhello.a to arduino-helloworld-lib\src\esp32 or arduino-helloworld-lib\src\esp8266 depending on which gcc you use to create the archive file.
|
||||||
|
|
||||||
|
Step 4:
|
||||||
|
|
||||||
|
Invoke the function from Ardunio sketch. example.ino
|
||||||
|
|
||||||
|
#include <hello.h> // hello.h header from our library (arduino-helloworld-lib)
|
||||||
|
|
||||||
|
#define BAUD_RATE 9600
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(BAUD_RATE);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// put your main code here, to run repeatedly:
|
||||||
|
int result = add(1, 1); // Invokes the add function in libhello.a
|
||||||
|
Serial.println(result);
|
||||||
|
delay(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
10
arduino-helloworld-lib/library.properties
Normal file
10
arduino-helloworld-lib/library.properties
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
name=hello
|
||||||
|
version=1.0.0
|
||||||
|
author=aruna
|
||||||
|
maintainer=aruna
|
||||||
|
sentence=A simple library
|
||||||
|
architectures=esp32
|
||||||
|
includes=hello.h
|
||||||
|
paragraph=
|
||||||
|
precompiled=true
|
||||||
|
url=https://www.sinric.com
|
BIN
arduino-helloworld-lib/src/esp32/libhello.a
Normal file
BIN
arduino-helloworld-lib/src/esp32/libhello.a
Normal file
Binary file not shown.
6
arduino-helloworld-lib/src/hello.h
Normal file
6
arduino-helloworld-lib/src/hello.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef HELLO_H
|
||||||
|
#define HELLO_H
|
||||||
|
|
||||||
|
int add(int x, int y);
|
||||||
|
|
||||||
|
#endif
|
15
example/example.ino
Normal file
15
example/example.ino
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include <hello.h>
|
||||||
|
|
||||||
|
#define BAUD_RATE 9600
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(BAUD_RATE);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// put your main code here, to run repeatedly:
|
||||||
|
int result = add(1, 1);
|
||||||
|
Serial.println(result);
|
||||||
|
delay(1000);
|
||||||
|
}
|
9
lib/hello.cpp
Normal file
9
lib/hello.cpp
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#include "hello.h"
|
||||||
|
|
||||||
|
int add(int x, int y) {
|
||||||
|
return x + y;
|
||||||
|
}
|
||||||
|
|
||||||
|
// C:\Users\user\AppData\Local\Arduino15\packages\esp32\tools\xtensa-esp32-elf-gcc\gcc8_4_0-esp-2021r2-patch3\bin
|
||||||
|
// xtensa-esp32-elf-gcc.exe -c hello.cpp -o hello.o
|
||||||
|
// xtensa-esp32-elf-ar.exe crf hello.a hello.o
|
6
lib/hello.h
Normal file
6
lib/hello.h
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef HELLO_H
|
||||||
|
#define HELLO_H
|
||||||
|
|
||||||
|
int add(int x, int y);
|
||||||
|
|
||||||
|
#endif
|
Loading…
x
Reference in New Issue
Block a user