Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Including built-in libraries within a custom library fails to compile when header file name does not match source file name #5079

Closed
1 task done
chuckz1 opened this issue Feb 3, 2025 · 2 comments

Comments

@chuckz1
Copy link

chuckz1 commented Feb 3, 2025

What kind of issue is this?

  • PlatformIO Core.
    If you’ve found a bug, please provide an information below.

Configuration

Operating system:
Windows 10 Home Version 22H2(OS Build 19045.5371)

PlatformIO Version (platformio --version):
PlatformIO Core, version 6.1.16

Target Hardware:
esp32doit-devkit-v1

Description of problem

When developing a custom library, compilation will fail if a built-in library is included from a .cpp file within the custom library. Compilation will only pass if the custom library has a header file(.h) with the same name as the .cpp file. It must be in the same folder as the .cpp file and must be included from a .cpp file from the main program. The header file can be completely empty and it will still compile.

Steps to Reproduce

  1. Create a custom library (source files below)
  2. Include a built-in library (such as ArduinoOTA) from a .cpp file in the library
  3. Include the library in another project
  4. Make one of these breaking changes
    • Comment out the "#include <custom.h>" from the main.cpp file
    • Change the custom.h to any other name (update include in main.cpp to the new name to avoid unknown file errors)
    • Move custom.h to a different folder such as an include folder (update include in main.cpp to the new path to avoid unknown file errors if needed).
  5. Try to compile the project

Actual Results

When you make any of the breaking changes you get this error message:

Compiling .pio\build\esp32doit-devkit-v1\lib22f\temp\custom.cpp.o
pathToProject/temp/src/custom.cpp:10:10: fatal error: ArduinoOTA.h: No such file or directory

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

 #include <ArduinoOTA.h>
          ^~~~~~~~~~~~~~
compilation terminated.
*** [.pio\build\esp32doit-devkit-v1\lib22f\temp\custom.cpp.o] Error 1

Expected Results

The compilation should have found the built-in library and complied properly like it does without the breaking changes.

Source files for reproduction:

The content of platformio.ini:

[env:esp32doit-devkit-v1]
platform = espressif32
board = esp32doit-devkit-v1
framework = arduino
monitor_speed = 115200
lib_deps = 
	symlink://PathToCustomLibrary

Main project source files to reproduce issue:

main.cpp

// main.cpp

#include <Arduino.h>

// empty header file with the same name as the .cpp file
// commenting this out will cause the compilation error
#include <custom.h>

// header that includes the function definitions
#include <linking.h>

void setup()
{
	Serial.begin(115200);
	Serial.println("Setup complete");
}

void loop()
{
	sayHello();
}

Custom Library structure

  • src/custom.cpp
  • src/custom.h
  • src.linking.h
  • library.json

Custom Library Source files to reproduce issue:

custom.cpp:

// custom.cpp

#include <Arduino.h>

// separate header file with different name to demonstate that the empty header file is required
#include "linking.h"

// Fails when including built-in ota library if header file is changed or not included
// commenting this include out will allow compliation without the empty header file
#include <ArduinoOTA.h>

// also fails with the sd library
//  #include "FS.h"
//  #include "SD.h"
//  #include "SPI.h"

void sayHello()
{
	Serial.println("Hello World");
	delay(1000);
}

custom.h:

// custom.h
// completely empty
// Renaming or moving this file to another folder (such as an include folder) will cause compliation to fail

linking.h:

// linking.h

void sayHello();

library.json

{
	"name": "Template_Library",
	"version": "1.0.0",
	"description": "Basic Hello world example library",
	"keywords": "example, library, Hello world",
	"frameworks": "arduino",
	"platforms": "*"
}

Additional info

This only fails for built-in libraries. Other libraries included as dependencies of the custom library will be found and compile correctly.

@vortigont
Copy link
Contributor

@chuckz1 you might try the fix from #4941 to see if it helps

@chuckz1
Copy link
Author

chuckz1 commented Feb 7, 2025

That fixed the issue. Thank you for the help. I didn't realize this was a duplicate.

@chuckz1 chuckz1 closed this as completed Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants