Problem with dependencies - my own files

Description of problem

I can’t compile my program with files in such a localisation:

│   .gitignore
│   .travis.yml
│   LICENSE
│   platformio.ini
│
├───.pioenvs
├───.vscode
│
├───include
│
├───lib
│       definitions.h
│       functions.cpp
│       functions.h
│       global_variables.h
│       initialization.cpp
│       initialization.h
│
└───src
         main.cpp

But when I move to include, everything works. Also, when trying to add /lib to c_cpp_properties.json that file keeps reseting, after VSCode restart.

Configuration

VS Code: 1.34.0
Home: 2.0.2
Core: 3.6.7
OS: Microsoft Windows [Version 10.0.17763.504]

Error message

While compiling

> Executing task: C:\Users\mateu\.platformio\penv\Scripts\platformio.exe run <

Processing nanoatmega328 (platform: atmelavr; board: nanoatmega328; framework: arduino)
--------------------------------------------------------------------------------------------------------------------------------------------------------------
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/atmelavr/nanoatmega328.html
PLATFORM: Atmel AVR > Arduino Nano ATmega328
HARDWARE: ATMEGA328P 16MHz 2KB RAM (30KB Flash)
Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF MODES: FINDER(chain) COMPATIBILITY(soft)
Collected 5 compatible libraries
Scanning dependencies...
No dependencies
Compiling .pioenvs\nanoatmega328\src\main.cpp.o
Compiling .pioenvs\nanoatmega328\FrameworkArduino\Stream.cpp.o
src\main.cpp:2:25: fatal error: definitions.h: No such file or directory

*********************************************************************
* Looking for definitions.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:definitions.h"
* Web  > https://platformio.org/lib/search?query=header:definitions.h
*
*********************************************************************

compilation terminated.
Compiling .pioenvs\nanoatmega328\FrameworkArduino\Tone.cpp.o
Compiling .pioenvs\nanoatmega328\FrameworkArduino\USBCore.cpp.o
*** [.pioenvs\nanoatmega328\src\main.cpp.o] Error 1
================================================================= [ERROR] Took 0.90 seconds =================================================================
The terminal process terminated with exit code: 1

Terminal will be reused by tasks, press any key to close it.

Do not manually edit the c_cpp_properties.json file, instead adapt the platformio.ini so that PlatformIO will generate the correct one for you.

Wrong folder structure, inside lib/ there should be your library folder (e.g. MyCoolLibrary), and in that folder there should be source files (can also be inside src/) The README file generated in the lib fodler says


This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link into executable file.

The source code of each library should be placed in a an own separate directory
("lib/your_library_name/[here are source files]").

For example, see a structure of the following two libraries `Foo` and `Bar`:

|--lib
|  |
|  |--Bar
|  |  |--docs
|  |  |--examples
|  |  |--src
|  |     |- Bar.c
|  |     |- Bar.h
|  |  |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
|  |
|  |--Foo
|  |  |- Foo.c
|  |  |- Foo.h
|  |
|  |- README --> THIS FILE
|
|- platformio.ini
|--src
   |- main.c

and a contents of `src/main.c`:

#include <Foo.h>
#include <Bar.h>

int main (void)
{
  ...
}


PlatformIO Library Dependency Finder will find automatically dependent
libraries scanning project source files.

More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html
1 Like