[UPDATE]
The error log as below
'Building target: USBHostC270_example_GR-PEACH.elf'
'Invoking: Cross ARM C++ Linker'
arm-none-eabi-g++ @"USBHostC270_example_GR-PEACH.elf.in"
c:/program files (x86)/gnu tools arm embedded/8 2019-q3-update/bin/../lib/gcc/arm-none-eabi/8.3.1/../../../../arm-none-eabi/bin/ld.exe: ./USBHost_custom_Addiso/USBisochronous/USBIsochronous.o: in function `HCITD::operator new(unsigned int, int)':
C:\Users\HoangSHC\e2_studio\workspace\USBHostC270_example_GR-PEACH\Debug/../USBHost_custom_Addiso/USBisochronous/USBIsochronous.h:41: undefined reference to `posix_memalign'
c:/program files (x86)/gnu tools arm embedded/8 2019-q3-update/bin/../lib/gcc/arm-none-eabi/8.3.1/../../../../arm-none-eabi/bin/ld.exe: C:\Users\HoangSHC\e2_studio\workspace\USBHostC270_example_GR-PEACH\Debug/../USBHost_custom_Addiso/USBisochronous/USBIsochronous.h:42: undefined reference to `posix_memalign'
c:/program files (x86)/gnu tools arm embedded/8 2019-q3-update/bin/../lib/gcc/arm-none-eabi/8.3.1/../../../../arm-none-eabi/bin/ld.exe: ./USBHost_custom_Addiso/USBisochronous/USBIsochronous.o: in function `_HCED::operator new(unsigned int)':
C:\Users\HoangSHC\e2_studio\workspace\USBHostC270_example_GR-PEACH\Debug/../USBHost_custom_Addiso/USBisochronous/USBIsochronous.h:99: undefined reference to `posix_memalign'
collect2.exe: error: ld returned 1 exit status
make: *** [USBHostC270_example_GR-PEACH.elf] Error 1
makefile:125: recipe for target 'USBHostC270_example_GR-PEACH.elf' failed
[SOLVE]
Origin source code
void* p;
if (posix_memalign(&p, 256, size) == 0) {
return p;
}
return NULL;
Replace to memalign
void* p;
p = memalign(256, size);
return p;
For details
inline void* operator new(size_t size) {
void* p;
#if !defined (__CC_ARM) && (!defined (_POSIX_C_SOURCE) || (_POSIX_C_SOURCE >= 200112L))
p = memalign(256, size);
return p;
#else
if (posix_memalign(&p, 256, size) == 0) {
return p;
}
return NULL;
#endif
}
After changing, I got this error: undefined reference to `__wrap__memalign_r'
'Building target: USBHostC270_example_GR-PEACH.elf'
'Invoking: Cross ARM C++ Linker'
arm-none-eabi-g++ @"USBHostC270_example_GR-PEACH.elf.in"
c:/program files (x86)/gnu tools arm embedded/8 2019-q3-update/bin/../lib/gcc/arm-none-eabi/8.3.1/../../../../arm-none-eabi/bin/ld.exe: c:/program files (x86)/gnu tools arm embedded/8 2019-q3-update/bin/../lib/gcc/arm-none-eabi/8.3.1/../../../../arm-none-eabi/lib/thumb/v7+fp/hard\libc.a(lib_a-malign.o): in function `memalign':
malign.c:(.text.memalign+0xe): undefined reference to `__wrap__memalign_r'
collect2.exe: error: ld returned 1 exit status
make: *** [USBHostC270_example_GR-PEACH.elf] Error 1
makefile:125: recipe for target 'USBHostC270_example_GR-PEACH.elf' failed
Then followed this
to solve the problem.
For E2 Studio right click to project > Properties > C/C++ Build > Settings > Cross ARM C++ Linker > Miscellaneous > Linker flags (-Xlinker [option])
Linker flags (-Xlinker [option])
--wrap=_malloc_r
--wrap=_free_r
--wrap=_realloc_r
--wrap=_memalign_r
--wrap=_calloc_r
adding '_' symbol before the flags
--wrap=__malloc_r
--wrap=__free_r
--wrap=__realloc_r
--wrap=__memalign_r
--wrap=__calloc_r
[RESEARCH]
After comparing stdlib.h between older version 4.9 (4.9 2015q3) and current version 8 (8 2019-q3-update). I thought that posix_memalign maybe not supported anymore
In version 8
arm-none-eabi/include/stdlib.h (not support posix_memalign)
#if __POSIX_VISIBLE >= 200112
int posix_memalign (void **, size_t, size_t) __nonnull((1))
__result_use_check;
#endif
arm-none-eabi/include/sys/features.h
#define _POSIX_C_SOURCE 200809L
In version 4.9
arm-none-eabi/include/stdlib.h (support posix_memalign)
#ifdef __rtems__
int _EXFUN(posix_memalign,(void **, size_t, size_t));
#endif
The GNU page says
9.637 posix_memalign
Gnulib module: —
Portability problems not fixed by Gnulib:
This function is missing on some platforms: Mac OS X 10.5, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, Minix 3.1.8, AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 10, Cygwin 1.5.x, mingw, MSVC 14, Interix 3.5, BeOS, Android 4.1.
Read more in