c++ global object methods not linked -


I am facing a problem with the C ++ project for STM32 ARM Micro, I made a class that The state implements the machine. This class has some methods that are not directly called in other ways, but only by function pointer:

  // Foo.h square fu {public: typefif zero (Foo :: * State) (zero); State state; Zero init (); Virtual Zero Surveys (); Zero State 1 (); Zero State 2 (); Fu (); Virtual ~ fu () {}}; // Foo.cpp #Include "Foo.h" # Defined by ASSIGN_STATE (X, Y) \ x = and FU :: state # # Y; Zero Foo :: init () {ASSIGN_STATE (state, 1); } Zero Foo :: state1 () {ASSIGN_STATE (state, 2); } Zero Fu :: state 2 () {; } Zero Foo :: poll () {(this- & gt; * state) (); } Foo :: Foo () {This-> Init (); }  

I instciciate the purpose of this class with the global class:

  foo foo; Int main () {foo.init (); While (1) foo.poll (); Return (1); }  

If I compile the project then those methods can be directly linked to other methods ( state1 () and state2 () ) Is not called.

Instead, I instill them within main () , the methods are linked and everything works properly.

ex> int main () {Foo foo; Foo.init (); While (1) foo.poll (); Return (1); }

Compiler and Linker Flags:

  COMPILER_FLAGS = $ (DEBUG_FLAGS) -mcpu = Cortex -M3 -mthumb -Wall -mlittle-endian -MD - MP -MF $ (deps) / $ (@f: ..% o =% d) -fno- Strict aliasing -fsigned- Four -ffunction classes -fdata classes $ (defines) $ (included) CPPCOMPILER_FLAGS = $ (DEBUG_FLAGS) -mcpu = Cortex-M3 -mthumb -Wall -mlittle-endian -MD -MP -MF $ (deps) / $ (@f: ..% o =% d) -fno- Strict aliasing -by-dated- Four -function classes -fdata classes -fno-RTTI -fno-exception $ (defines) $ (included) LINKER_FLAGS = -mcpu = Cortex -M3 -mthumb -specs = nano.specs -lnosys L $ (LINKERSCRIPT_DIR) - T $ (LINK_SCRI PT) -Wl, - GC-squares $ (DEFINES)  

Project C / C + is composite I use GCC ARM Tools Toolken to compile it under Windows 7 OS .

I tried with different compiler flags and different optimization options, but nothing changed because the reason I get this behavior is how can I check its causes, or any thoughts on it?

After the text itemprop = "text">

what is happening is that the part of your code is being collected by Linker because it thinks That is it is not referenced anywhere. I have seen that it is only accessible with an ISR code because GCC could not see any reference between the main code and the ISR.

The -function sections and -fdata-sections that you specify in each of your projects, automatically designated for each function and data items section is created, then when it gets to the linker, then you get the -Wl, - gc-sections , which causes the linker to drop all redirected sections from the output. This is a great thing on MCU because it lowers your program memory usage. Unfortunately, as I mentioned, the compiler is not perfect in identifying unused codes.

In the past, I have declared an indicator through the declared object inside that code which is definitely fine and to ensure that I start it in the main code. The compiler sees outgoing references and does not collect function / data garbage.

You can also resolve by moving that data / function which is disappearing in a section which does not collect garbage once GCC section attribute, for example, You can use the __ attribute (__ (section (". Text"))) to move the function.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -