Undefined reference errors when using libwebp library

Hi everyone,
I’m trying to use libwebp library in my Arduino project to decode animated webp images.

At the moment the sketch is pretty basic, as I removed everything but the webp part.

I’m getting this error during linking:

Compiling .pio/build/webp/src/main.cpp.o
Linking .pio/build/webp/firmware.elf
.pio/build/webp/src/main.cpp.o:(.literal._Z8testWebpv+0x4): undefined reference to `WebPAnimDecoderOptionsInitInternal'
.pio/build/webp/src/main.cpp.o:(.literal._Z8testWebpv+0x8): undefined reference to `WebPAnimDecoderNewInternal'
.pio/build/webp/src/main.cpp.o:(.literal._Z8testWebpv+0xc): undefined reference to `WebPAnimDecoderGetInfo'
.pio/build/webp/src/main.cpp.o:(.literal._Z8testWebpv+0x10): undefined reference to `WebPAnimDecoderHasMoreFrames'
.pio/build/webp/src/main.cpp.o:(.literal._Z8testWebpv+0x14): undefined reference to `WebPAnimDecoderGetNext'
.pio/build/webp/src/main.cpp.o:(.literal._Z8testWebpv+0x18): undefined reference to `WebPAnimDecoderReset'
.pio/build/webp/src/main.cpp.o:(.literal._Z8testWebpv+0x1c): undefined reference to `WebPAnimDecoderDelete'
.pio/build/webp/src/main.cpp.o: In function `testWebp()':
/Users/carlos/projects/esp32/test-webp/src/main.cpp:27: undefined reference to `WebPAnimDecoderOptionsInitInternal'
/Users/carlos/projects/esp32/test-webp/src/main.cpp:27: undefined reference to `WebPAnimDecoderNewInternal'
/Users/carlos/projects/esp32/test-webp/src/main.cpp:27: undefined reference to `WebPAnimDecoderGetInfo'
/Users/carlos/projects/esp32/test-webp/src/main.cpp:27: undefined reference to `WebPAnimDecoderHasMoreFrames'
/Users/carlos/projects/esp32/test-webp/src/main.cpp:27: undefined reference to `WebPAnimDecoderGetNext'
/Users/carlos/projects/esp32/test-webp/src/main.cpp:27: undefined reference to `WebPAnimDecoderReset'
/Users/carlos/projects/esp32/test-webp/src/main.cpp:27: undefined reference to `WebPAnimDecoderDelete'
collect2: error: ld returned 1 exit status
*** [.pio/build/webp/firmware.elf] Error 1

main.cpp (based on webp2gif) tool:

#include <Arduino.h>
#include <webp/demux.h>

void testwebp();

void setup(){
    Serial.begin(115200);
    delay(1000);
    Serial.println("Setting up...");
}

void loop() {
    delay(5000);
	testwebp();
}

void testwebp() {
	WebPAnimDecoderOptions webp_dec_options;
	WebPAnimDecoderOptionsInit(&webp_dec_options);
	webp_dec_options.color_mode = MODE_RGBA;
	webp_dec_options.use_threads = true;
	WebPData webp_data;
	webp_data.size = 1024;
	webp_data.bytes = new uint8_t[webp_data.size];
	WebPAnimDecoder* webp_dec = WebPAnimDecoderNew(&webp_data, &webp_dec_options);
	WebPAnimInfo webp_anim_info;
	WebPAnimDecoderGetInfo(webp_dec, &webp_anim_info);

	int curr_timestamp = 0;
  // int prev_timestamp = 0;
	while(WebPAnimDecoderHasMoreFrames(webp_dec)){
		uint8_t* rgba_buffer;
		WebPAnimDecoderGetNext(webp_dec, &rgba_buffer, &curr_timestamp);
		printf("test\n");
		// prev_timestamp = curr_timestamp;
	}
	WebPAnimDecoderReset(webp_dec);
	WebPAnimDecoderDelete(webp_dec);
}

my directory structure looks like:

test-webp
├── .pio
├── include
│   └── README
├── lib
│   ├── README
│   └── libwebp
│       ├── library.json
│       └── src
│           ├── Makefile.am
│           ├── dec
│           ├── demux
│           ├── dsp
│           ├── enc
│           ├── libwebp.pc.in
│           ├── libwebp.rc
│           ├── libwebpdecoder.pc.in
│           ├── libwebpdecoder.rc
│           ├── mux
│           ├── utils
│           └── webp
├── platformio.ini
├── src
│   └── main.cpp

lib/libwebp/library.json:

{
    "name": "libwebp",
    "build": {
        "srcFilter": [
            "+<src/**/*.c>"
        ],
        "unflags": [
            "-DHAVE_CONFIG_H"
        ]
    }
}

platformio.ini:

[env:webp]
platform = espressif32
board = esp32doit-devkit-v1
framework = arduino
board_build.f_cpu = 240000000L
monitor_speed = 115200
monitor_filters = esp32_exception_decoder
upload_port = /dev/cu.SLAB_USBtoUART

I’m running Visual Studio Code v1.55.2, running on MacOS Mojave, and PlatformIO Core v5.1.1.

I guess it’s not finding the definition of those functions, but I’m not sure what I should add/change to make it work.

Any suggestions would be much appreciated.

Thanks!

Your srcFilter expression is causing every C file to be ignored.

Just replace the library.json file with

{
    "name": "libwebp",
    "build": {
        "unflags": [
            "-DHAVE_CONFIG_H"
        ],
        "flags": [
            "-I."
        ]
    }
}
1 Like

Thank you @maxgerhardt! That did the trick! Now it’s building correctly