2024-04-19 08:30 AM
I'm working on a state machine for a console application, and I would like to use std::strings in C++, as they are much nicer to work with than C-style strings.
Including the string library does not result in errors, but when I call string objects in the code I start to get errors. Here's an example of the code I am using:
//const char* output; //No errors in c-style strings
std::string(output); //Compiles, but results in linker error
switch(mState)
{
case MAIN_STATE:
output = "\r\nmain->";
break;
case CAN_STATE:
output = "\r\ncan->";
break;
case UART_STATE:
output = "\r\nuart->";
break;
case GPIO_STATE:
output = "\r\ngpio->";
break;
default:
output = "\r\nMAIN->";
break;
}
//Print(output); //No errors with C-style Strings
Print(output.c_str()); //Compiles, but results in linker error
As I indicated in the code comments, any time I call a function from the <string> library, I get the following linker error:
07:41:57 **** Incremental Build of configuration Default for project ConsoleApp ****
make -j28 all
Compiling cConsole.cpp
Linking build/out.elf
c:/spc5studio-6.0/eclipse/plugins/com.st.tools.spc5.tools.gnu.gcc.ppcvle.win32_4.9.4.20200908161514/toolchain/bin/../lib/gcc/powerpc-eabivle/4.9.4/../../../../powerpc-eabivle/lib/e200z4\libc.a(lib_a-abort.o):
In function `abort':
abort.c:(.text.abort+0x10): undefined reference to `_exit'
c:/spc5studio-6.0/eclipse/plugins/com.st.tools.spc5.tools.gnu.gcc.ppcvle.win32_4.9.4.20200908161514/toolchain/bin/../lib/gcc/powerpc-eabivle/4.9.4/../../../../powerpc-eabivle/lib/e200z4\libc.a(lib_a-sbrkr.o):
In function `_sbrk_r':
sbrkr.c:(.text._sbrk_r+0x1a): undefined reference to `sbrk'
c:/spc5studio-6.0/eclipse/plugins/com.st.tools.spc5.tools.gnu.gcc.ppcvle.win32_4.9.4.20200908161514/toolchain/bin/../lib/gcc/powerpc-eabivle/4.9.4/../../../../powerpc-eabivle/lib/e200z4\libc.a(lib_a-signalr.o):
In function `_kill_r':
signalr.c:(.text._kill_r+0x1c): undefined reference to `kill'
c:/spc5studio-6.0/eclipse/plugins/com.st.tools.spc5.tools.gnu.gcc.ppcvle.win32_4.9.4.20200908161514/toolchain/bin/../lib/gcc/powerpc-eabivle/4.9.4/../../../../powerpc-eabivle/lib/e200z4\libc.a(lib_a-signalr.o):
In function `_getpid_r':
signalr.c:(.text._getpid_r+0x0): undefined reference to `getpid'
collect2.exe: error: ld returned 1 exit status
make: *** [components/spc58ecxx_platform_component_rla/lib/rsc/rules.mk:164: build/out.elf] Error 1
"make -j28 all" terminated with exit code 2. Build might be incomplete.
07:42:06 Build Failed. 5 errors, 0 warnings. (took 9s.6ms)
Interestingly, I've also noticed these kinds of errors with other standard C++ Libraries like <array> or <vector>.
These are my current linker settings:
What do I need to change in my linker settings to get the standard C++ libraries to link/build correctly?
Solved! Go to Solution.
2024-04-24 01:01 AM
Yes, it is possible but it is not so easy
i recommend to follow to create the missing function in your project
Solved: SPC5Studio cannot use the malloc() and free() func... - STMicroelectronics Community
Best Regards
Erwan
2024-04-24 01:01 AM
Yes, it is possible but it is not so easy
i recommend to follow to create the missing function in your project
Solved: SPC5Studio cannot use the malloc() and free() func... - STMicroelectronics Community
Best Regards
Erwan