<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Reboot when declaring object inside main method</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/89100/reboot-when-declaring-object-inside-main-method</link><description>Hello every body. 
 I have created my own objects and when I was testing some configuration I realized about the following: 
 
 1. When I declare the objects outside the main method (as global) the program runs perfectly. 
 2. When I declare the objects</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 24 Jun 2022 06:43:32 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/89100/reboot-when-declaring-object-inside-main-method" /><item><title>RE: Reboot when declaring object inside main method</title><link>https://devzone.nordicsemi.com/thread/374053?ContentTypeID=1</link><pubDate>Fri, 24 Jun 2022 06:43:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f6cec687-bca2-402b-8606-95e6758f9411</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="Leonardo Santa"]I incremented the memory stack size and it worked perfectly (it worked without the static keyword).[/quote]
&lt;p&gt;That is good to hear.&amp;nbsp;&lt;/p&gt;
[quote user="Leonardo Santa"]However, I would like to understand some errors that I got during the implementation of th[/quote]
&lt;p&gt;CONFIG_CPP_STATIC_INIT_GNU is not user configurable as the error you got stated, but it is enabled by default - so in any case there is no need to set it. To use it though you need to use non-standard GNU specific way of doing it, but I&amp;nbsp;have not found out how you would do that (and to be frank,&amp;nbsp;my C++ is quite rusty). I do not see enough of your code to say if that would be sensibel anyway though, but I originally intended it just as a simple test (which it turned out not to be &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reboot when declaring object inside main method</title><link>https://devzone.nordicsemi.com/thread/373987?ContentTypeID=1</link><pubDate>Thu, 23 Jun 2022 14:31:40 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6e769a22-7315-4592-924f-938262680b94</guid><dc:creator>LeoSanta</dc:creator><description>&lt;p&gt;Hi Einar. Thank you for your help.&lt;/p&gt;
&lt;p&gt;I incremented the memory stack size and it worked perfectly (it worked without the static keyword).&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;However, I would like to understand some errors that I got during the implementation of this:&lt;/p&gt;
&lt;p&gt;If I put static keyword, I got this error:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;main.cpp:113: undefined reference to `__cxa_guard_release&amp;#39;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:240px;max-width:320px;" src="https://devzone.nordicsemi.com/resized-image/__size/640x480/__key/communityserver-discussions-components-files/4/pastedimage1655994400083v2.png" alt=" " /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I also tried adding in the prj.conf the following:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;CONFIG_CPP_STATIC_INIT_GNU=y&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;But I got the following error:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;error: CPP_STATIC_INIT_GNU (defined at c:\NRF52833\timer\timer_test_1\build\subsys\cpp\Kconfig:78) is assigned in a configuration file,
but is not directly user-configurable (has no prompt). It gets its value indirectly from other
symbols. See http://docs.zephyrproject.org/latest/reference/kconfig/CONFIG_CPP_STATIC_INIT_GNU.html
and/or look up CPP_STATIC_INIT_GNU in the menuconfig/guiconfig interface. The Application
Development Primer, Setting Configuration Values, and Kconfig - Tips and Best Practices sections of
the manual might be helpful too.&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reboot when declaring object inside main method</title><link>https://devzone.nordicsemi.com/thread/373841?ContentTypeID=1</link><pubDate>Thu, 23 Jun 2022 07:47:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:c0a867f1-0ae3-486f-9c86-b11c8b605f6a</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;How does it fail now? And did you try to simply increase the stack size? If you don&amp;#39;t make progress, perhaps you can upload the failing project here along with instructions on how to build it so that I can have a look?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reboot when declaring object inside main method</title><link>https://devzone.nordicsemi.com/thread/373759?ContentTypeID=1</link><pubDate>Wed, 22 Jun 2022 15:38:24 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f90f0d32-8e78-4679-8fc5-27438bb675a1</guid><dc:creator>LeoSanta</dc:creator><description>&lt;p&gt;The problem is exacly the stack. However, when I put the static keyword to the object inside the main method it does not compile the .cpp file even after I put&amp;nbsp;CONFIG_CPP_STATIC_INIT_GNU=y at the config file.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reboot when declaring object inside main method</title><link>https://devzone.nordicsemi.com/thread/373165?ContentTypeID=1</link><pubDate>Mon, 20 Jun 2022 08:11:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:3ac81f94-f5a3-44fb-bb84-92beb7a05c5d</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;The first thing that comes to mind is a stack overflow issue. A global object is never on the stack, but when you declare it within a function it will be on the stack unless you make it static. So a simple way to see if this could be it is to make it static (by using the &lt;code&gt;static&lt;/code&gt; keyword when you declare it) and see if the issue persists. If you are using the nRF Connect SDK you can also add a stack guard and check the debug log to see if that is it (CONFIG_MPU_STACK_GUARD). You can use CONFIG_MAIN_STACK_SIZE to increase the main stack size.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>