[SOLVED] arm-none-eabi-g++ global object declaration inheritance problems
hi, background working on arduino core (approximately) stm32f373 using, arm-none-eabi-g++ https://launchpad.net/gcc-arm-embedded/+download.
here simple c++ source file:
i having strange problem globally declared objects: above code hangs , doesn't print if "derived" declared globally, works fine if declared inside loop() (and prints "3"). using following cflags , ldflags
but have indeed tried take out optimizations or code size reduction options without seeming difference.
an additional symptom if have class constructor, , declare instance global, constructor seems not called. not of expert c++, hints @ appreciated! additionally if isn't right forum this, i'd glad if moved moderator.
here simple c++ source file:
code: [select]
class base {
public:
virtual int purevirt() = 0;
int othermethod() { return purevirt() + 1; }
};
class derived: public base {
public:
int purevirt() { return 2; }
};
// global declaration
derived derived;
void setup() {
serial1.begin(115200);
}
void loop() {
// or, local declaration
// derived derived;
serial1.print(derived.othermethod());
delay(100);
}
i having strange problem globally declared objects: above code hangs , doesn't print if "derived" declared globally, works fine if declared inside loop() (and prints "3"). using following cflags , ldflags
code: [select]
cflags = -o2 -os -wall -werror-implicit-function-declaration -wno-sign-compare -wno-strict-aliasing -wdouble-promotion -fno-rtti
cflags += -mlittle-endian -mthumb -mcpu=cortex-m4
cflags += -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fsingle-precision-constant
cflags += -fno-common -fno-exceptions -ffunction-sections -fdata-sections -nostartfiles
cflags += -ffast-math
cflags += -darm_math_cm4 -d'__fpu_present=1'
ldflags = $(cflags)
ldflags += --static -wl,--gc-sections -wl,-map,$(builddir)/$(projname).map -nostartfiles -t$(stm32dir)/vendor/st/stm32_flash.ld -specs=nano.specs -lm -u _printf_float
but have indeed tried take out optimizations or code size reduction options without seeming difference.
an additional symptom if have class constructor, , declare instance global, constructor seems not called. not of expert c++, hints @ appreciated! additionally if isn't right forum this, i'd glad if moved moderator.
the problem startup code (meant c programs) wasn't calling __init_array_start. temporary solution call them explicitly myself:
code: [select]
extern void (*__preinit_array_start []) (void) __attribute__((weak));
extern void (*__preinit_array_end []) (void) __attribute__((weak));
extern void (*__init_array_start []) (void) __attribute__((weak));
extern void (*__init_array_end []) (void) __attribute__((weak));
int main() {
// libc_init_array -- handles global constructors
unsigned int count;
unsigned int i;
count = __preinit_array_end - __preinit_array_start;
(i = 0; < count; i++)
__preinit_array_start[i] ();
count = __init_array_end - __init_array_start;
(i = 0; < count; i++)
__init_array_start[i] ();
// ... other stuff ...
}
Arduino Forum > Development > Other Software Development > [SOLVED] arm-none-eabi-g++ global object declaration inheritance problems
arduino
Comments
Post a Comment