Undefined reference to `xPortGetFreeHeapSizeCaps(unsigned int)

abcdcadb
Posts: 36
Joined: Mon Aug 07, 2017 1:28 am

Undefined reference to `xPortGetFreeHeapSizeCaps(unsigned int)

Postby abcdcadb » Wed Nov 15, 2017 9:38 am

I tried using xPortGetFreeHeapSizeCap to check the free heap of esp.

I create a "reference.c" in the same folder with main.c, inside reference.c I define reference function:

Code: Select all

#include"reference.h"
extern "C" {
#include "esp_heap_alloc_caps.h"
}
extern void SmbDaemon()
{
printf( "\n entered checking function");.

printf("\n free 32bit heap is %d",xPortGetFreeHeapSizeCaps(MALLOC_CAP_32BIT));

}
in "reference.h" i declare:

Code: Select all

extern void SmbDaemon()
. and in main.c i call SmbDaemon()

i got this

Code: Select all

" Undefined reference to `xPortGetFreeHeapSizeCaps(unsigned int) when compiling"
if i remove "printf("\n free 32bit heap is %d",xPortGetFreeHeapSizeCaps(MALLOC_CAP_32BIT));" i can compile and enter SmbDaemon()

However, If i directly call printf("\n free 32bit heap is %d",xPortGetFreeHeapSizeCaps(MALLOC_CAP_32BIT))in main.c, code can be compiled and work well.
what should i modify?

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Undefined reference to `xPortGetFreeHeapSizeCaps(unsigned int)

Postby kolban » Wed Nov 15, 2017 5:48 pm

I'm not fully following your puzzle ... but I see that xPortGetFreeHeapSizeCaps() has been deprecated in favor of heap_caps_get_free_heap_size(). May I suggest that you read the docs on that API and replace your reference to xPortGetFreeHeapSizeCaps() in your source with the new API.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

abcdcadb
Posts: 36
Joined: Mon Aug 07, 2017 1:28 am

Re: Undefined reference to `xPortGetFreeHeapSizeCaps(unsigned int)

Postby abcdcadb » Thu Nov 16, 2017 12:13 am

Iam working on idf 2.0 and there is another function is esp_get_free_heap_size.
however, it gives different result from xPortGetFreeHeapSizeCap and I dont know which is more trustworthy

may i will try IDF 3.0

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Undefined reference to `xPortGetFreeHeapSizeCaps(unsigned int)

Postby ESP_Angus » Thu Nov 16, 2017 4:03 am

If your source is really .c and not .cpp then try removing the extern "C" block from around the #include.

Do you get any other warnings or errors from the compiler before that one?

abcdcadb
Posts: 36
Joined: Mon Aug 07, 2017 1:28 am

Re: Undefined reference to `xPortGetFreeHeapSizeCaps(unsigned int)

Postby abcdcadb » Thu Nov 16, 2017 4:50 am

previously, i didnt have extern C, i added it after reviewing some posts, the result is identical.

it almost finishes compiling (it can recognize esp_heap_alloc_caps.h) and being export reference.o file, the error occurs and stop

ESP_Angus
Posts: 2344
Joined: Sun May 08, 2016 4:11 am

Re: Undefined reference to `xPortGetFreeHeapSizeCaps(unsigned int)

Postby ESP_Angus » Thu Nov 16, 2017 5:35 am

Can you please post the full output of "make V=1"?

Please copy it onto a site like https://pastebin.com or https://gist.github.com and then post a link to the forum.

Who is online

Users browsing this forum: No registered users and 175 guests