Everything works perfectly before running the compiler.
I made a dummy class to test this and reproduce the issue
Project:
lib/dummy/dummy.h
#ifndef dummy_h
#define dummy_h
#include <Arduino.h>
class dummy{
bool garb = true;
void print();
};
#endif
lib/dummy/dummy.cpp
#include “dummy.h”
void dummy::print(){
Serial.println(“garbage”);
}
src/main.cpp
#include <Arduino.h>
#include <dummy.h>
#define SERIAL_BAUD 115200 //baud rate for serial monitor
void setup(){
Serial.begin(SERIAL_BAUD, SERIAL_8N1, SERIAL_TX_ONLY);
while (!Serial)
;
}
void loop(){
dummy x = dummy();
x.print();
delay(1000);
}
As anyone can see, this is basic.
but linker throws this:
.pioenvs/nodemcuv2/src/main.cpp.o:(.text.loop+0x3c): undefined reference to dummy::print()' .pioenvs/nodemcuv2/src/main.cpp.o: In function
loop’:
main.cpp:(.text.loop+0x8a): undefined reference to `dummy::print()’
I want to switch from eclipse (with sloeber ) to platform io because i love atom a LOT.
When i port my project to eclipse it links everything perfectly fine …
i have no goddamn idea why…
1 Like
My setup:
$ pio --version
PlatformIO, version 3.6.0a6
Platform Espressif 8266
--------
Updating espressif8266 @ 1.7.3 [Up-to-date]
Updating framework-esp8266-rtos-sdk @ 1.5.0-beta.5 [Up-to-date]
Updating toolchain-xtensa @ 1.40802.0 [Up-to-date]
Updating tool-esptool @ 1.413.0 [Up-to-date]
Updating tool-mkspiffs @ 1.200.0 [Up-to-date]
Updating tool-espotapy @ 1.1.1 [Up-to-date]
Updating framework-arduinoespressif8266 @ 1.20401.2 [Up-to-date]
Updating framework-esp8266-nonos-sdk @ 2.1.0 [Up-to-date]
When I compile above thing I just get the error
lib\dummy/dummy.h: In function 'void loop()':
lib\dummy/dummy.h:6:7: error: 'void dummy::print()' is private
void print();
To solve just put
#ifndef dummy_h
#define dummy_h
#include <Arduino.h>
class dummy {
bool garb = true;
public:
void print();
};
#endif
After that:
DATA: [==== ] 40.5% (used 33156 bytes from 81920 bytes)
PROGRAM: [== ] 24.8% (used 258576 bytes from 1044464 bytes)
[SUCCESS] Took 9.10 seconds
So, I can’t reproduce the above. Does the dependency graph show the dummy
library and does it try to compile the dummy.cpp
file? Are you updated on all things? (pio upgrade --dev
, pio platform update
)
one second, i’ll make screenshots and upload em somewhere because i can’t explain this in any other way, thanks for attempting anyways.
the dummy class is in the same files as the config_class, no difference though, and yeah i just fergot the public: statement before ( in the post, not the source code).
the original problem was myde by the class config_class.
What board did you use ? i tried nodemcu v1 (becuase that’sthe one i got) did you use a different one ?
After removing the warnings for signed vs unsigned comparisons:
My platformio.ini
[env:esp8266]
platform = espressif8266
board = nodemcuv2
framework = arduino
upload_speed = 921600
Hm, well maybe obj
is a bad name for a library because obj
is where temporary object files are compiled and are maybe skipped / ignored.
Screenshots are not of much use, I’d need to see the full build log. You can do a pio run -t clean && pio run -v > build_log.txt 2>&1
in the console within your project folder and upload that to pastebin.
renamed the obj → my big class
platform.ini made no difference
https://hastebin.com/yabebayoqi.coffeescript
Well the config_class
isn’t showing up as a sub item of my_big_class
|-- <my_big_class> (/home/zweieuro/Documents/PlatformIO/Projects/home_ctl_port/lib/my_big_class)
| |-- <dusk_dawn_calc> (/home/zweieuro/Documents/PlatformIO/Projects/home_ctl_port/lib/dusk_dawn_calc)
| |-- <transmitter> (/home/zweieuro/Documents/PlatformIO/Projects/home_ctl_port/lib/transmitter)
| | |-- <receiver> (/home/zweieuro/Documents/PlatformIO/Projects/home_ctl_port/lib/receiver)
| |-- <ESP8266HTTPClient> 1.1 (/home/zweieuro/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266HTTPClient)
| | |-- <ESP8266WiFi> 1.0 (/home/zweieuro/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266WiFi)
| |-- <temp_hum_sens> (/home/zweieuro/Documents/PlatformIO/Projects/home_ctl_port/lib/temp_hum_sens)
| | |-- <Wire> 1.0 (/home/zweieuro/.platformio/packages/framework-arduinoespressif8266/libraries/Wire)
| |-- <ArduinoJson> 5.13.2 (/home/zweieuro/.platformio/lib/ArduinoJson_ID64)
| |-- <Wire> 1.0 (/home/zweieuro/.platformio/packages/framework-arduinoespressif8266/libraries/Wire)
| |-- <infra> (/home/zweieuro/Documents/PlatformIO/Projects/home_ctl_port/lib/infra)
| | |-- <IRremoteESP8266> 2.4.2 (/home/zweieuro/.platformio/lib/IRremoteESP8266_ID1089)
| | |-- <ESP8266WiFi> 1.0 (/home/zweieuro/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266WiFi)
| |-- <ESP8266WiFi> 1.0 (/home/zweieuro/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266WiFi)
Try adding lib_ldf_mode = chain+
to you platformio.ini
to make the library dependency finder more aggressive. (or deep+)
Out of my hat I can’t think of reasons why the LDF doesn’t find your library (maybe rename from confIg_class.*
to something else? there shouldn’t be any magic names though). If you can reproduce the problem in a minimal project I can have a look at that (or your project code if you don’t mind), but that is what the first 2 posts were about and that works (at 1 level of indentation).
tried it with the flag for the dependency finder, didn’t work.
i’ll try to make a small project out of it.
if i cna’T reproduce it there you can have the whole thing, this platform is great and i want to help improving it if i get the chance ^^
i tried it in it’s own project but that worked fine.
where and how should i upload the project so you can look at it ?
Maybe try to rename all the folders, file and class names to the ones in the project making the problems first? Otherwise github would be a standard place to upload stuff. Or just ZIP the project and put it on dropbox / google drive
Weirdly enough PIO isn’t able to handle multiple level of folders correctly…
A minimal project shows:

dummy.cpp
#include "dummy.h"
void dummy::print(){
Serial.println("garbage");
}
dummy.h
#ifndef dummy_h
#define dummy_h
#include <Arduino.h>
class dummy {
bool garb = true;
public:
void print();
};
#endif
main.cpp
#include <Arduino.h>
#include <config_class/dummy.h>
#define SERIAL_BAUD 115200 //baud rate for serial monitor
void setup() {
Serial.begin(SERIAL_BAUD, SERIAL_8N1, SERIAL_TX_ONLY);
while (!Serial);
}
void loop() {
dummy x = dummy();
x.print();
delay(1000);
}
Shows the same problem
.pioenvs\esp8266\src\main.cpp.o:(.text.loop+0x0): undefined reference to `dummy::print()'
.pioenvs\esp8266\src\main.cpp.o: In function `loop':
main.cpp:(.text.loop+0x11): undefined reference to `dummy::print()'
collect2.exe: error: ld returned 1 exit status
@zweieuro You have a pull-request with a fix on your repo now.
1 Like
THANK YOU !!!
yeah for some reason it seems it can’t handle layers…
Shouldn’t we report this somewhere ? It seems like a pretty severe problem tbh…
also It’S weird… in the readme from platform IO which is in your lib folder, it specifies this case as example …
1 Like
The only one level is supported in lib
folder.
With the new build system in V4, can this be supported?