How do I include a local file? This is my project structure (with multiple sketches):
(project root)
- some_config.json
- SketchOne/
- SketchOne.ino
- SketchTwo/
- SketchTwo.ino
- lib/
- lib_1/
- some.h
From SketchOne/SketchOne.ino, I want to include lib/lib_1/some.h. I've tried the following(s):
#include "lib/lib_1/some.h"
#include <lib/lib_1/some.h>
#include "lib_1/some.h"
#include <lib_1/some.h>
Note: I use the CLI (arduino-cli)
-
maybe it would be a better idea to use a SD Module. So later you can change data by replacing the SD-Card and reboot. mischianti.org/2020/01/26/… Using a local JSON-File is not useful. You also could convert the JSON to an inline array within the program code. You can use quicktype.io to convert the JSON ...Danny– Danny2022年09月06日 09:25:18 +00:00Commented Sep 6, 2022 at 9:25
2 Answers 2
In Arduino projects are called "sketches". The name of the main ino file of the sketch must match the name of the sketch folder. CLI builds one sketch at time.
Sketches are in file system organized into a folder called "sketchbook". The sketchbook folder should containing a special folder named "libraries". Folders in the libraries folder are treated as libraries. There are two forms of library folder in the file system: old and new.
See the sketch build process too.
3 Comments
arduino-cli. I feel like it can work but I need to play with --library and --libraries flag(s)--library although was adding two libraries (comma-separated)I installed arduino-cli and used the following Makefile to include Cpp native libraries:
NAME = mod10
MODULE ?= XXX.ino
ARDUINO_CLI = arduino-cli.exe
ARDUINO_CLI_DIR = /mnt/c/arduino-cli
# Arduino CLI Board type
BOARD_TYPE ?= arduino:avr:uno
SERIAL_PORT ?= COM5
# Optional verbose compile/upload trigger
V ?= 0
VERBOSE=
INCLUDES="C:/Program Files (x86)/Windows Kits/10/Include/10.0.22621.0/ucrt,C:/Program Files/Microsoft Visual Studio/2022/Professional/VC/Tools/MSVC/14.38.33130/include"
# Build path -- used to store built binary and object files
BUILD_DIR=_build
PWD ?= /path/to/ino/file/folder/
BUILD_PATH=$(PWD)/$(BUILD_DIR)
SKETCH=$(MODULE)
ifneq ($(V), 0)
VERBOSE=-v
endif
.PHONY: all verify program clean
all: verify
verify:
echo "Compiling $(SKETCH)"
mkdir -p $(BUILD_PATH)
$(ARDUINO_CLI_DIR)/$(ARDUINO_CLI) compile $(VERBOSE) --library=$(INCLUDES) --build-path=$(BUILD_PATH) --build-cache-path=$(BUILD_PATH) -b $(BOARD_TYPE) $(SKETCH)
$(NAME):
echo $(PWD)
$(ARDUINO_CLI_DIR)/$(ARDUINO_CLI) upload $(VERBOSE) -p $(SERIAL_PORT) --fqbn $(BOARD_TYPE) $(SKETCH)
clean:
@rm $(PWD)/*.elf
@rm $(PWD)/*.hex
I used the flag --library and the variable $INCLUDES contains the absolute paths to the native CPP libraries I wanted to add, separated by a comma
Comments
Explore related questions
See similar questions with these tags.