<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Using object from another file]]></title><description><![CDATA[<p dir="auto">I have a project with the main .ino file and a separate class (configuration.h+configration.cpp)</p>
<p dir="auto">My ino file looks like this:</p>
<pre><code>#include &lt;ArduinoLog.h&gt; // MIT license, https://github.com/thijse/Arduino-Log
#include "Configuration.h"
void setup() {
#ifndef DISABLE_LOGGING
  Serial.begin(9600);
  Log.begin(LOG_LEVEL_VERBOSE, &amp;Serial);
#endif
  Log.verbose(F("Starting up." CR));
}
</code></pre>
<p dir="auto">The sketch works, as long as I don't try to use Log in my configuration class.</p>
<p dir="auto">The configuration.cpp file looks like this:</p>
<pre><code>uint8_t Configuration::readData(uint8_t address) {
  Log.verbose(F("readData was called" CR));
  return 4; // Dummy for now
}
</code></pre>
<p dir="auto">When compiling, the Log object is not available. I get this error:</p>
<pre><code>configuration.cpp:21: error: 'Log' was not declared in this scope
</code></pre>
<p dir="auto">What is a clean and efficient way to make the log function available in my other class(es)?</p>
]]></description><link>https://forum.mysensors.org/topic/7864/using-object-from-another-file</link><generator>RSS for Node</generator><lastBuildDate>Sat, 15 Aug 2026 16:41:19 GMT</lastBuildDate><atom:link href="https://forum.mysensors.org/topic/7864.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 25 Oct 2017 11:50:40 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Using object from another file on Wed, 25 Oct 2017 18:10:29 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bulldoglowell" aria-label="Profile: BulldogLowell">@<bdi>BulldogLowell</bdi></a> it is just not the way I expected to do it.</p>
]]></description><link>https://forum.mysensors.org/post/78194</link><guid isPermaLink="true">https://forum.mysensors.org/post/78194</guid><dc:creator><![CDATA[mfalkvidd]]></dc:creator><pubDate>Wed, 25 Oct 2017 18:10:29 GMT</pubDate></item><item><title><![CDATA[Reply to Using object from another file on Wed, 25 Oct 2017 15:33:03 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mfalkvidd" aria-label="Profile: mfalkvidd">@<bdi>mfalkvidd</bdi></a> said in <a href="/post/78177">Using object from another file</a>:</p>
<blockquote>
<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bulldoglowell" aria-label="Profile: BulldogLowell">@<bdi>BulldogLowell</bdi></a> I was hoping to avoid including ArduinoLog in all .h files, but there seems to be no way around that.</p>
</blockquote>
<p dir="auto">what's the problem with adding the #include directive?  It is a dependency by definition....</p>
]]></description><link>https://forum.mysensors.org/post/78179</link><guid isPermaLink="true">https://forum.mysensors.org/post/78179</guid><dc:creator><![CDATA[BulldogLowell]]></dc:creator><pubDate>Wed, 25 Oct 2017 15:33:03 GMT</pubDate></item><item><title><![CDATA[Reply to Using object from another file on Wed, 25 Oct 2017 15:29:57 GMT]]></title><description><![CDATA[<p dir="auto">don't include ArduinoLog.h in header files, only in cpp files.</p>
]]></description><link>https://forum.mysensors.org/post/78178</link><guid isPermaLink="true">https://forum.mysensors.org/post/78178</guid><dc:creator><![CDATA[rozpruwacz]]></dc:creator><pubDate>Wed, 25 Oct 2017 15:29:57 GMT</pubDate></item><item><title><![CDATA[Reply to Using object from another file on Wed, 25 Oct 2017 15:27:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/bulldoglowell" aria-label="Profile: BulldogLowell">@<bdi>BulldogLowell</bdi></a> I was hoping to avoid including ArduinoLog in all .h files, but there seems to be no way around that.</p>
<p dir="auto">I guess some sort of dependency injection would work, but dependency injection and embedded code might not work well together.</p>
]]></description><link>https://forum.mysensors.org/post/78177</link><guid isPermaLink="true">https://forum.mysensors.org/post/78177</guid><dc:creator><![CDATA[mfalkvidd]]></dc:creator><pubDate>Wed, 25 Oct 2017 15:27:50 GMT</pubDate></item><item><title><![CDATA[Reply to Using object from another file on Wed, 25 Oct 2017 15:36:33 GMT]]></title><description><![CDATA[<p dir="auto">Where is Log declared?</p>
<p dir="auto">it is a global  and defined in the CPP file for the Logging class:</p>
<pre><code>Logging Log = Logging();
</code></pre>
<p dir="auto">so, if it is Global... why the heck can't it be accessed in the Configuration class?  Well each set of files is a different translation unit...</p>
<p dir="auto">Have you tried adding</p>
<pre><code>#include &lt;ArduinoLog.h&gt;
</code></pre>
<p dir="auto">in your</p>
<pre><code>"Configuration.h"
</code></pre>
<p dir="auto">class?</p>
]]></description><link>https://forum.mysensors.org/post/78176</link><guid isPermaLink="true">https://forum.mysensors.org/post/78176</guid><dc:creator><![CDATA[BulldogLowell]]></dc:creator><pubDate>Wed, 25 Oct 2017 15:36:33 GMT</pubDate></item><item><title><![CDATA[Reply to Using object from another file on Wed, 25 Oct 2017 14:53:55 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rozpruwacz" aria-label="Profile: rozpruwacz">@<bdi>rozpruwacz</bdi></a> cool. Thanks a lot!</p>
]]></description><link>https://forum.mysensors.org/post/78175</link><guid isPermaLink="true">https://forum.mysensors.org/post/78175</guid><dc:creator><![CDATA[mfalkvidd]]></dc:creator><pubDate>Wed, 25 Oct 2017 14:53:55 GMT</pubDate></item><item><title><![CDATA[Reply to Using object from another file on Wed, 25 Oct 2017 14:33:21 GMT]]></title><description><![CDATA[<p dir="auto">oh, and maybe the most important, Log is an object not a class :)</p>
]]></description><link>https://forum.mysensors.org/post/78174</link><guid isPermaLink="true">https://forum.mysensors.org/post/78174</guid><dc:creator><![CDATA[rozpruwacz]]></dc:creator><pubDate>Wed, 25 Oct 2017 14:33:21 GMT</pubDate></item><item><title><![CDATA[Reply to Using object from another file on Wed, 25 Oct 2017 14:32:18 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mfalkvidd" aria-label="Profile: mfalkvidd">@<bdi>mfalkvidd</bdi></a> no. I'm assuming that Log object is declared in some cpp file of the library You use. And there is a header file that has something like this:<br />
extern X Log;<br />
X is the class of the Log object.<br />
then if you include the header file in multiple cpp files, there still will be only one Log object. You just have to make sure that the Log.begin will be called once (in one of the cpp files or ino file) before any other calls to the Log object in other cpp/ino files.</p>
]]></description><link>https://forum.mysensors.org/post/78173</link><guid isPermaLink="true">https://forum.mysensors.org/post/78173</guid><dc:creator><![CDATA[rozpruwacz]]></dc:creator><pubDate>Wed, 25 Oct 2017 14:32:18 GMT</pubDate></item><item><title><![CDATA[Reply to Using object from another file on Wed, 25 Oct 2017 14:26:56 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/rozpruwacz" aria-label="Profile: rozpruwacz">@<bdi>rozpruwacz</bdi></a> that would mean I have to call Log.begin in all cpp files as well, right? So if I want to change the log level from VERBOSE to NOTICE, or the log target from Serial to something else, I would have to edit all cpp files?</p>
<p dir="auto">That seems very inelegant and inefficient to me. But I am not very skilled in c/c++. Maybe I'm just spoiled by other languages that has better ways to handle this?</p>
]]></description><link>https://forum.mysensors.org/post/78172</link><guid isPermaLink="true">https://forum.mysensors.org/post/78172</guid><dc:creator><![CDATA[mfalkvidd]]></dc:creator><pubDate>Wed, 25 Oct 2017 14:26:56 GMT</pubDate></item><item><title><![CDATA[Reply to Using object from another file on Wed, 25 Oct 2017 13:55:03 GMT]]></title><description><![CDATA[<p dir="auto">you have to include header file with Log definition in every cpp file in which you want to use Log objects.</p>
]]></description><link>https://forum.mysensors.org/post/78171</link><guid isPermaLink="true">https://forum.mysensors.org/post/78171</guid><dc:creator><![CDATA[rozpruwacz]]></dc:creator><pubDate>Wed, 25 Oct 2017 13:55:03 GMT</pubDate></item></channel></rss>