Страница 1 из 1
new + stm32 [РЕШЕНО]
Добавлено: Пн дек 23, 2013 14:47:07
gruffi
Добрый день, форумчане! Возник вопрос по-поводу выделения памяти для динамического массива:
Вот хедер:
Код: Выделить всё
#ifndef CKEYBOARD_H_
#define CKEYBOARD_H_
#include <stdint.h>
//---------------------------
typedef struct BUTTON_DefType
{
uint32_t id; // id кнопки
void (*process)(void); // функция обрабатывающая нажатие кнопки
}BUTTON;
//-------------
class CKeyboard
{
private:
uint32_t m_numButton; // количество кнопок
BUTTON *m_buttons; // указатель на массив кнопок
public:
CKeyboard(uint32_t numBut);
~CKeyboard();
};
#endif /* CKEYBOARD_H_ */
Вот реализация:
Код: Выделить всё
#include "CKeyboard.h"
//--------------------------------------------------------
CKeyboard::CKeyboard(uint32_t numBut): m_numButton(numBut)
{
m_buttons = new BUTTON[m_numButton];
}
//---------------------
CKeyboard::~CKeyboard()
{
delete[] m_buttons;
}
При компилировании возникает ошибка - collect2.exe: error: ld returned 1 exit status
Если выделение памяти производить через malloc, то все компилируется без проблем. В чем может быть ошибка?
Re: new + stm32
Добавлено: Пн дек 23, 2013 15:58:57
balmer
gruffi писал(а):ld returned 1 exit status
Это последняя ошибка, означает что не получилось слинковать программу.
Там до этого должны быть еще ошибки.
Re: new + stm32
Добавлено: Пн дек 23, 2013 16:09:05
gruffi
Да извините недоглядел. Вот вывод из консоли:
Спойлер
**** Build of configuration Debug for project timer ****
cs-make all
'Building file: ../src/CKeyboard/CKeyboard.cpp'
'Invoking: ARM Windows GCC C++ Compiler (Sourcery Lite Bare)'
arm-none-eabi-g++ -Os -ffunction-sections -fdata-sections -Wall -Wa,-adhlns="src/CKeyboard/CKeyboard.o.lst" -fno-exceptions -fno-rtti -funsigned-bitfields -c -fmessage-length=0 -MMD -MP -MF"src/CKeyboard/CKeyboard.d" -MT"src/CKeyboard/CKeyboard.d" -mcpu=cortex-m3 -mthumb -g3 -o "src/CKeyboard/CKeyboard.o" "../src/CKeyboard/CKeyboard.cpp"
'Finished building: ../src/CKeyboard/CKeyboard.cpp'
' '
'Building file: ../src/main.cpp'
'Invoking: ARM Windows GCC C++ Compiler (Sourcery Lite Bare)'
arm-none-eabi-g++ -Os -ffunction-sections -fdata-sections -Wall -Wa,-adhlns="src/main.o.lst" -fno-exceptions -fno-rtti -funsigned-bitfields -c -fmessage-length=0 -MMD -MP -MF"src/main.d" -MT"src/main.d" -mcpu=cortex-m3 -mthumb -g3 -o "src/main.o" "../src/main.cpp"
'Finished building: ../src/main.cpp'
' '
'Building target: timer.elf'
'Invoking: ARM Windows GCC C++ Linker (Sourcery Lite Bare)'
arm-none-eabi-g++ -T"C:\ARM\Development\Workspace\timer\system\gcc_cs.ld" -Xlinker --gc-sections -Wl,-Map,"timer.map" -mcpu=cortex-m3 -mthumb -g3 -o "timer.elf" ./system/startup_ARMCM3.o ./system/system_stm32f10x.o ./src/CKeyboard/CKeyboard.o ./src/main.o
c:/arm/sourcery_codebench_lite_for_arm_eabi/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib/thumb2\libcs3unhosted.a(unhosted-_close.o): warning: IO function '_close' used
c:/arm/sourcery_codebench_lite_for_arm_eabi/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib/thumb2\libcs3unhosted.a(unhosted-_fstat.o): warning: IO function '_fstat' used
c:/arm/sourcery_codebench_lite_for_arm_eabi/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib/thumb2\libcs3unhosted.a(unhosted-isatty.o): warning: IO function '_isatty' used
c:/arm/sourcery_codebench_lite_for_arm_eabi/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib/thumb2\libcs3unhosted.a(unhosted-_kill.o): warning: IO function '_kill' used
c:/arm/sourcery_codebench_lite_for_arm_eabi/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib/thumb2\libcs3unhosted.a(unhosted-_lseek.o): warning: IO function '_lseek' used
c:/arm/sourcery_codebench_lite_for_arm_eabi/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib/thumb2\libcs3unhosted.a(unhosted-_read.o): warning: IO function '_read' used
c:/arm/sourcery_codebench_lite_for_arm_eabi/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/lib/thumb2\libcs3unhosted.a(unhosted-_write.o): warning: IO function '_write' used
c:/arm/sourcery_codebench_lite_for_arm_eabi/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/bin/ld.exe: timer.elf section `.text' will not fit in region `rom'
c:/arm/sourcery_codebench_lite_for_arm_eabi/bin/../lib/gcc/arm-none-eabi/4.8.1/../../../../arm-none-eabi/bin/ld.exe: region `rom' overflowed by 36720 bytes
collect2.exe: error: ld returned 1 exit status
cs-make: *** [timer.elf] Error 1
**** Build Finished ****
Re: new + stm32
Добавлено: Пн дек 23, 2013 16:10:41
gruffi
я так понял это перерасход памяти rom. Неужели оператор new столько жрет?
Re: new + stm32
Добавлено: Пн дек 23, 2013 17:07:02
gruffi
Все вопрос решен

. Тема закрыта. Для моих нужд подойдет и статический массив

. При динамическом выделении памяти с помощью malloc размер прошивки увеличился в 8 раз...