tobozo/YAMLDuino

Undefined Reference to `deserializeYml`

Closed this issue ยท 5 comments

I have the following code:

...

#include <SD.h>
#include <SPI.h>
#include <FS.h>
#include <ArduinoJson.h>
#include <YAMLDuino.h>

...

void SdHelpers::readInTagInfo(){
	File file = SD.open(tagInfoFileName);
	
	if( !file ) {
		LifeHelpers::unrecoverableError("Can't open config file for reading.");
	}

	DynamicJsonDocument jsonDoc(2048);
	auto err = deserializeYml(jsonDoc, file); // convert yaml to json
	file.close();
	
	if( err ) {
		LifeHelpers::unrecoverableError(String("Unable to deserialize YAML to JsonDocument: ") + String(err.c_str()));
	}
	
	JsonObject configJson = jsonDoc.as<JsonObject>();

	TagInfo newInfo(configJson);
	
	SdHelpers::tagInfoObj = newInfo;
}

Which seems to get past the compiler's syntax check, but when fails during the linking process:

~/.arduino15/packages/esp32/tools/xtensa-esp32s3-elf-gcc/gcc8_4_0-esp-2021r2-patch5/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld: sketch/SdHelpers.cpp.o:(.literal._ZN9SdHelpers13readInTagInfoEv+0x20): undefined reference to `YAML::libyaml_arduinojson::deserializeYml(ArduinoJson6200_F1::JsonDocument&, Stream&)'
~/.arduino15/packages/esp32/tools/xtensa-esp32s3-elf-gcc/gcc8_4_0-esp-2021r2-patch5/bin/../lib/gcc/xtensa-esp32s3-elf/8.4.0/../../../../xtensa-esp32s3-elf/bin/ld: sketch/SdHelpers.cpp.o: in function `SdHelpers::readInTagInfo()':
~/gitRepos/NameTag/arduinoSketch/NameTag/SdHelpers.cpp:14: undefined reference to `YAML::libyaml_arduinojson::deserializeYml(ArduinoJson6200_F1::JsonDocument&, Stream&)'
collect2: error: ld returned 1 exit status
exit status 1
Error compiling for board UM FeatherS3.

Any ideas?

tobozo commented

hi, thanks for your feedback ๐Ÿ‘

it's possible the __has_include(<ArduinoJson.h>) fails if YAMLduino.h was already included from somewhere else in the project, it can also happen when the project libraries are precompiled by a linker that ignores the other libraries (e.g. platformio can do that when some ldf flags are enabled).

one thing you can try is to add this before including YAMLduino.h:

#define HAS_ARDUINOJSON

Thanks for the quick response!

Unfortunately, that didn't seem to do the trick...

I added #define HAS_ARDUINOJSON before each YAMLduino include, but still the same I think...

If you want a closer look, here is my code:

All the code:
https://github.com/GregJohnStewart/NameTag/tree/main/arduinoSketch/NameTag

Where the includes are:
https://github.com/GregJohnStewart/NameTag/blob/main/arduinoSketch/NameTag/SdHelpers.h

Erring code:
https://github.com/GregJohnStewart/NameTag/blob/main/arduinoSketch/NameTag/SdHelpers.cpp#L12

I also include ArduinoJson and YAMLduino in InfoPart and TagInfo.

.... And I think I resolved the issue....

I restarted my computer just in case, and lo and behold things compile now. Thanks for your time!

tobozo commented

Restarting the arduino IDE was probably enough to fix that: when toggling any HAS_* flag, some namespaces get overwritten but their cache isn't invalidated and next compilation may fail.

You can see it happen when you compile twice in a row, but the cached files are supposed to get flushed when any of the cpp file is modified.

image

Lack of cache invalidation could be an effect of the messy detection macros, or an espressif bug.

Including the same external library from multiple places in your source folder tends to slow down compilation and isn't exactly the best practice though.

I am having this issue but all tips here have not helped. Any ideas?