<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/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/"><channel><title>C++ global object multiple defined</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/35528/c-global-object-multiple-defined</link><description> 
Hello: 
I&amp;#39;m coding in C++ for ARM for the first time, using Keil. I&amp;#39;m
working in a project that already exists but I need to make some
changes. I cannot change the libraries or the file&amp;#39;s
structure. The test_1 and test_2 functions use a global object</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: C++ global object multiple defined</title><link>https://community.arm.com/thread/133854?ContentTypeID=1</link><pubDate>Tue, 27 Feb 2018 04:25:21 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:94d0db93-a593-4798-87ed-bd1ec730479f</guid><dc:creator>Rods Caps</dc:creator><description>&lt;p&gt;&lt;p&gt;
Hello Hans:&lt;br /&gt;
The code was not &lt;b&gt;linking&lt;/b&gt;.&lt;br /&gt;
Now I corrected it and it is compiling, linking and running.&lt;/p&gt;

&lt;p&gt;
Thanks you very much for your help&lt;/p&gt;

&lt;p&gt;
regards&lt;br /&gt;
Rods&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ global object multiple defined</title><link>https://community.arm.com/thread/133855?ContentTypeID=1</link><pubDate>Tue, 27 Feb 2018 04:23:40 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:eef87839-aa6f-45a8-9e5b-c87bd2b4a5e6</guid><dc:creator>Rods Caps</dc:creator><description>&lt;p&gt;&lt;p&gt;
Hello Robert:&lt;br /&gt;
That was the problem! I reviwed the code and instead of&lt;/p&gt;

&lt;pre&gt;
extern myclass mc;
&lt;/pre&gt;

&lt;p&gt;
I was using&lt;/p&gt;

&lt;pre&gt;
extern myclass mc();
&lt;/pre&gt;

&lt;p&gt;
. I was confusing object with function.&lt;br /&gt;
Thank you very much for your help.&lt;/p&gt;

&lt;p&gt;
Regards&lt;br /&gt;
Rods&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ global object multiple defined</title><link>https://community.arm.com/thread/109433?ContentTypeID=1</link><pubDate>Mon, 26 Feb 2018 12:39:57 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:fa1554c0-58a6-45a3-a152-36d79655e4d0</guid><dc:creator>HansBernhard Broeker</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;I cannot change this class and the code don&amp;#39;t compile without a
value there.&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Doesn&amp;#39;t &lt;b&gt;compile&lt;/b&gt;, or doesn&amp;#39;t &lt;b&gt;link&lt;/b&gt;? The distinction is
crucial. And what is &amp;quot;this class&amp;quot; that you cannot change?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ global object multiple defined</title><link>https://community.arm.com/thread/109430?ContentTypeID=1</link><pubDate>Mon, 26 Feb 2018 09:48:35 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:83e3b7d6-9365-4bb7-b7ec-bc6c91972434</guid><dc:creator>Robert McNamara</dc:creator><description>&lt;p&gt;&lt;p&gt;
What error are you getting why you declare it like this?&lt;/p&gt;

&lt;pre&gt;
extern myclass mc;  // extern declaration
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ global object multiple defined</title><link>https://community.arm.com/thread/94354?ContentTypeID=1</link><pubDate>Mon, 26 Feb 2018 08:17:10 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:89665adf-adbc-450e-883d-9865bdbb944c</guid><dc:creator>Rods Caps</dc:creator><description>&lt;p&gt;&lt;p&gt;
Thanks for your insights Hans.&lt;br /&gt;
I believe the line you pointed is a definition beacuse the
initialization value &amp;quot;0&amp;quot;, right?&lt;br /&gt;
I cannot change this class and the code don&amp;#39;t compile without a value
there.&lt;br /&gt;
The problem with this code is that the functions Test_1, Test_2,
etc... and some IRQ functions uses this object as global and I cannot
change the code.&lt;br /&gt;
Thanks,&lt;br /&gt;
Rods&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: C++ global object multiple defined</title><link>https://community.arm.com/thread/85647?ContentTypeID=1</link><pubDate>Mon, 26 Feb 2018 05:34:08 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:55804c90-c40e-4161-ac05-5a971e1ca152</guid><dc:creator>HansBernhard Broeker</dc:creator><description>&lt;p&gt;&lt;pre&gt;
&lt;i&gt;extern myclass mc(0);  // extern declaration&lt;/i&gt;
&lt;/pre&gt;

&lt;p&gt;
That&amp;#39;s your problem right there. That&amp;#39;s &lt;b&gt;not&lt;/b&gt; actually a
declaration. It&amp;#39;s a definition. So your code at large is in violation
of the C++ &amp;quot;one definition rule&amp;quot;. You have to fix that.&lt;/p&gt;

&lt;p&gt;
Your headers also fail to pull in the type definition for
&amp;quot;myclass&amp;quot; before using it. That means they can&amp;#39;t stand on their own,
which tends to create all kinds of problems down the road.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>