undefined reference to `malloc_align' error

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
tazz
Level 3
Level 3
100 sign-ins 10 questions asked 25 replies posted

hi we are getting           undefined reference to `malloc_align'.

code is 

void *th_aligned_malloc_x( size_t size, size_t align, const char *file, int line )

{
void *p;
/* avoid warnings since we are not using these */
file=file;
line=line;
p=malloc_align( size, align); /* file, line );*/

 

 

this malloc_align is called at 

#if defined( NO_ALIGNED_ALLOC )
#define malloc_aligned(size, align) malloc(size)
#define free_aligned(base) free(base)
#else
#if _MSC_VER
#define malloc_aligned(size, align) _aligned_malloc(size, align)
#define free_aligned(base) _aligned_free(base)
#else
#define malloc_aligned(size, align) ({void *p; (posix_memalign(&p, align, size) == 0) ? p : NULL;})
#define free_aligned(base) free(base)
#endif

0 Likes
1 Solution
Pradeep_PN
Moderator
Moderator
Moderator
250 sign-ins 100 solutions authored 25 likes received

Hi @tazz ,

Greetings from Infineon.
Are you trying to get the output from the UART if yes, then please refer the UART code example which  demonstrates a simple UART communication by printing the "Hello world" message on a terminal and blinking an LED using a timer resource.

Link:  https://github.com/Infineon/mtb-example-hal-hello-world

Let me know if you have any further queries.

Best Regards
Pradeep.

View solution in original post

0 Likes
13 Replies
Pradeep_PN
Moderator
Moderator
Moderator
250 sign-ins 100 solutions authored 25 likes received

Hi @tazz ,

Greetings from Infineon.

You have defined  _aligned_malloc(size, align) as malloc_aligned(size, align) but you have used

 p=malloc_align( size, align);
so can you please  change the   p=malloc_align( size, align);  to  p=malloc_aligned( size, align);
Can you please add  #endif at the end of declarations to end all the initiated if loops.

Hope this helps and kindly let me know if you need any further information.

Best Regards
Pradeep.

0 Likes
tazz
Level 3
Level 3
100 sign-ins 10 questions asked 25 replies posted

hi , thanks for response  made changes but getting error  "undefined reference to `posix_memalign'  "

 

void *p;
/* avoid warnings since we are not using these */
file=file;
line=line;
p=malloc_aligned( size, align); /* file, line );*/

 

 

 

 

#if defined( NO_ALIGNED_ALLOC )
#define malloc_aligned(size, align) malloc(size)
#define free_aligned(base) free(base)
#else
#if _MSC_VER
#define malloc_aligned(size, align) _aligned_malloc(size, align)
#define free_aligned(base) _aligned_free(base)
#else
#define malloc_aligned(size, align) ({void *p; (posix_memalign(&p, align, size) == 0) ? p : NULL;})
#define free_aligned(base) free(base)
#endif
#endif

 

 

regards

 

0 Likes
Pradeep_PN
Moderator
Moderator
Moderator
250 sign-ins 100 solutions authored 25 likes received

Hi @tazz ,

Greetings from Infineon.

We assume the error is coming  because you are trying to use a function that has not been declared. So please include the stdlib standard library into your code. 

#include "stdlib.h"  or   #include <stdlib.h>

Hope this helps and kindly let me know if you need any further information.

Best Regards
Pradeep.

0 Likes
tazz
Level 3
Level 3
100 sign-ins 10 questions asked 25 replies posted

hi #include "stdlib.h" was already attached to this code , but error is still there.

regards

 

0 Likes
Pradeep_PN
Moderator
Moderator
Moderator
250 sign-ins 100 solutions authored 25 likes received

Hi @tazz ,

Greetings from Infineon.

Can you please send me the entire  code so that we can assist you in a better way and can you please tell us which ide are you using?

Best Regards
Pradeep.

0 Likes
lock attach
Attachments are accessible only for community members.
tazz
Level 3
Level 3
100 sign-ins 10 questions asked 25 replies posted

hi we are uing modus toolbox version 3.0 , code files are attached

regards

0 Likes
Pradeep_PN
Moderator
Moderator
Moderator
250 sign-ins 100 solutions authored 25 likes received

Hi @tazz ,

Greetings from Infineon.

As you have defined many user defined header files, in order to check the project at my end I need all the user defined header files . So can you please send the entire  folder of the project where it contains all the user defined header files?

 

ppn_0-1681217468424.png

Can you please share the entire MTB folder of the project.

Best Regards
Pradeep.

 

0 Likes
tazz
Level 3
Level 3
100 sign-ins 10 questions asked 25 replies posted
0 Likes
Pradeep_PN
Moderator
Moderator
Moderator
250 sign-ins 100 solutions authored 25 likes received

Hi @tazz ,

Greetings from Infineon.

The above link is not working so kindly attach the compressed folder of the project.

Best Regards
Pradeep.

 

0 Likes
lock attach
Attachments are accessible only for community members.
tazz
Level 3
Level 3
100 sign-ins 10 questions asked 25 replies posted

please find the attached files

regards

 

0 Likes
Pradeep_PN
Moderator
Moderator
Moderator
250 sign-ins 100 solutions authored 25 likes received

Hi @tazz ,

Greetings from Infineon.

I had went through the code and found an build error which is  undefined reference to the  posix_memalign error.
This is because posix_memalign is not supported in the ARM GCC you are using .
So instead of posix_memalign use memalign which have the similar functionality.

Replace the following macro present in the th_cfg.h
#define malloc_aligned(size, align) ({void *p; (posix_memalign(&p, align, size) == 0) ? p : NULL;})

with

#define malloc_aligned(size, align) ({void *p; p=memalign(align,size);(p==0)? p : NULL;})

Hope this helps and kindly let me know if you need any further information.

Best Regards
Pradeep.

 

 

0 Likes
tazz
Level 3
Level 3
100 sign-ins 10 questions asked 25 replies posted

thank you for your reply error is gone, but on output nothing is coming. 

regards

0 Likes
Pradeep_PN
Moderator
Moderator
Moderator
250 sign-ins 100 solutions authored 25 likes received

Hi @tazz ,

Greetings from Infineon.
Are you trying to get the output from the UART if yes, then please refer the UART code example which  demonstrates a simple UART communication by printing the "Hello world" message on a terminal and blinking an LED using a timer resource.

Link:  https://github.com/Infineon/mtb-example-hal-hello-world

Let me know if you have any further queries.

Best Regards
Pradeep.

0 Likes