Включение библиотеки строк в другие файлы заголовков не приводит к ошибкам в процессе сборки. Однако когда я вызываю строковые объекты в коде, я начинаю получать ошибки компоновщика. Вот пример кода, который я использую:
Код: Выделить всё
//const char* output; //No errors with C-style Strings
std::string(output); //Compiles, but this line results in a linker error
switch(mState)
{
case MAIN_STATE:
output = "\r\nmain->";
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
Код: Выделить всё
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)
Настройки моего компоновщика Makefile приведены ниже:
р>
Код: Выделить всё
# Enable this if you want the linker to remove unused code and data.
ifeq ($(USE_LINK_GC),)
USE_LINK_GC = yes
endif
# Enable this if you want to use the C++ linker.
ifeq ($(USE_CPLUSPLUS_LINKER),)
USE_CPLUSPLUS_LINKER = yes
endif
# Linker options here.
ifeq ($(USE_LDOPT),)
USE_LDOPT = -lm,-lc,-z,max-page-size=16384
endif
Изменить: параметры компоновщика доступны мне в инструменте разработки SPC5

Подробнее здесь: https://stackoverflow.com/questions/783 ... string-use
Мобильная версия