Linker errors when using the "new" operator

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Linker errors when using the "new" operator

3,222 Views
villevallinder
Contributor II

Hello Everybody!

 

When I add something like "int* MyInt = new int;" to a C++ project I get the following result:

 

Invoking: Standard S32DS C++ Linker

powerpc-eabivle-g++ -o "Basic_Z4_1.elf" "@Basic_Z4_1.args"  

D:/Freescale/S32_Power_v1.0/S32DS/e200_ewl2/lib/fp/e200z4\libsupc++.a(vterminate.o): In function `__gnu_cxx::__verbose_terminate_handler()':

/home/rb501c/build_gcc_dir/build_gnu/opt/freescale/ELvle/obj_gcc/powerpc-eabivle/fp/e200z4/libstdc++-v3/libsupc++/../../../../../../src_gcc/libstdc++-v3/libsupc++/vterminate.cc:67: undefined reference to `_impure_ptr'

/home/rb501c/build_gcc_dir/build_gnu/opt/freescale/ELvle/obj_gcc/powerpc-eabivle/fp/e200z4/libstdc++-v3/libsupc++/../../../../../../src_gcc/libstdc++-v3/libsupc++/vterminate.cc:67: undefined reference to `_impure_ptr'

/home/rb501c/build_gcc_dir/build_gnu/opt/freescale/ELvle/obj_gcc/powerpc-eabivle/fp/e200z4/libstdc++-v3/libsupc++/../../../../../../src_gcc/libstdc++-v3/libsupc++/vterminate.cc:69: undefined reference to `_impure_ptr'

/home/rb501c/build_gcc_dir/build_gnu/opt/freescale/ELvle/obj_gcc/powerpc-eabivle/fp/e200z4/libstdc++-v3/libsupc++/../../../../../../src_gcc/libstdc++-v3/libsupc++/vterminate.cc:72: undefined reference to `_impure_ptr'

/home/rb501c/build_gcc_dir/build_gnu/opt/freescale/ELvle/obj_gcc/powerpc-eabivle/fp/e200z4/libstdc++-v3/libsupc++/../../../../../../src_gcc/libstdc++-v3/libsupc++/vterminate.cc:49: undefined reference to `_impure_ptr'

D:/Freescale/S32_Power_v1.0/S32DS/e200_ewl2/lib/fp/e200z4\libsupc++.a(vterminate.o):/home/rb501c/build_gcc_dir/build_gnu/opt/freescale/ELvle/obj_gcc/powerpc-eabivle/fp/e200z4/libstdc++-v3/libsupc++/../../../../../../src_gcc/libstdc++-v3/libsupc++/vterminate.cc:49: more undefined references to `_impure_ptr' follow

D:/Freescale/S32_Power_v1.0/S32DS/e200_ewl2/lib/fp/e200z4\libc.a(vsnprintf.o): In function `vsnprintf':

S32DS/e200_ewl/EWL_C/src/stdio/vsnprintf.c:58: undefined reference to `__pformatter'

D:/Freescale/S32_Power_v1.0/S32DS/e200_ewl2/lib/fp/e200z4\libc.a(abort.o): In function `abort':

S32DS/e200_ewl/EWL_C/src/stdlib/abort.c:34: undefined reference to `_ExitProcess'

D:/Freescale/S32_Power_v1.0/S32DS/e200_ewl2/lib/fp/e200z4\libc.a(alloc.o): In function `sbrk':

S32DS/e200_ewl/EWL_C/src/stdlib/alloc.c:285: undefined reference to `_end'

S32DS/e200_ewl/EWL_C/src/stdlib/alloc.c:285: undefined reference to `_end'

D:/Freescale/S32_Power_v1.0/S32DS/e200_ewl2/lib/fp/e200z4\libc.a(exit.o): In function `exit':

S32DS/e200_ewl/EWL_C/src/stdlib/exit.c:40: undefined reference to `__fini_cpp'

S32DS/e200_ewl/EWL_C/src/stdlib/exit.c:53: undefined reference to `_ExitProcess'

collect2.exe: error: ld returned 1 exit status

make: *** [Basic_Z4_1.elf] Error 1

 

Does anyone know the reason for this?

 

I have a proprietary implementation of "new" that I could use, is there a way to make DS use that one instead of the built-in one?

 

Thanks in advance!

 

Ville

Labels (1)
Tags (1)
0 Kudos
3 Replies

1,932 Views
stanish
NXP Employee
NXP Employee

Hello Ville,

Thanks for your contribution on NXP Community.

You cannot link the project since you selected EWL (Embedder Warrior Libraries).

The EWL libs are built with the smallest footprint by default. Therefore the libs does not include all the features - e.g. dynamic memory allocation routines.

The easiest way is to select "Newlib" libraries in the project Wizard (see below).

Other way is to customize EWL libs (using prefix .h files) and rebuild it.

S32DS_Power_create_CPP__newlib_project.png

Hope it helps.

Stan

0 Kudos

1,932 Views
villevallinder
Contributor II

Hello Stanislav!

I made a new project with newlib selected.

It still does not link but the issued error is completely different:

Invoking: Standard S32DS C++ Linker

powerpc-eabivle-g++ -o "Basic2_Z4_1.elf" "@Basic2_Z4_1.args"  

D:/Freescale/S32_Power_v1.0/Cross_Tools/powerpc-eabivle-4_9/powerpc-eabivle/newlib/lib/fp/e200z4\libnosys.a(sbrk.o): In function `sbrk':

/home/rb501c/build_gcc_dir/build_gnu/opt/freescale/ELvle/obj_newlib/powerpc-eabivle/fp/e200z4/libgloss/libnosys/../../../../../../src_newlib/libgloss/libnosys/sbrk.c:21: undefined reference to `end'

/home/rb501c/build_gcc_dir/build_gnu/opt/freescale/ELvle/obj_newlib/powerpc-eabivle/fp/e200z4/libgloss/libnosys/../../../../../../src_newlib/libgloss/libnosys/sbrk.c:21: undefined reference to `end'

collect2.exe: error: ld returned 1 exit status

make: *** [Basic2_Z4_1.elf] Error 1

Shouldn't DS add "end" to "sections.ld" based on selected memory layout?

__HEAP_SIZE is set to 0 in "mem.ld", is there a project setting for heap size somewhere?

Best Regards

Ville

0 Kudos

1,932 Views
villevallinder
Contributor II

I changed the heap size and added an "end" definition at the beginning of the heap section, it works just fine.

One thing I noticed though is that the newlib implementation of malloc allocates a minimium of 16 bytes even for single byte types.

The overhead is used internally and is probably useful/needed when running on a platform such as Linux.

In an embedded environment with limited RAM however, it may be a good idea to use something more rudimentary.

I'm going to stick with newlib for now but probably find a way to use my proprietary implementation in the future.

Thanks for your help Stanislav!

Ville

0 Kudos