user33100: Sorry if this question been asked. I'm trying to activate certain function in a class using a macro defined in the class from main.cpp. I'm using jrowberg MPU6050 library if that matters.
main.cpp
#include "gyro.h"
gyro gyro(Serial);
#define OUTPUT_READABLE_EULER

void setup(){
...
}
void loop(){
...
}

gyro.cpp
  #include "gyro.h"
  #ifdef OUTPUT_READABLE_EULER
      // display Euler angles in degrees
      mpu.dmpGetQuaternion(&q, fifoBuffer);
      mpu.dmpGetEuler(euler, &q);
      serial_.print("euler\t");
      serial_.print(euler[0] * 180/M_PI);
      serial_.print("\t");
      serial_.print(euler[1] * 180/M_PI);
      serial_.print("\t");
      serial_.println(euler[2] * 180/M_PI);
  #endif

If I define OUTPUT_READABLE_EULER in gyro.h, it works. But I want to do it from main.cpp.

user31105: You cannot not, but also you should not try to define a macro in a cpp file and use it in another cpp file.
Instead, you have to define it in a h (header) file, which is included in both cpp files.
Why would you define it in main.cpp or main.h anyway if you don't use it in those files?
You have mainly three options:

Define it in gyro.h so you include it in gyro.cpp where you use it. You can later use it in other files as well.
Define it in gyro.cpp so you can use it only in that file. This prevents the macro being used in other files (which can be safer).
Define it in a separate file, e.g. euler.h and include this header file everywhere you need it.

See also Juraj's comments below.

33100: <p>Sorry if this question been asked. I'm trying to activate certain function in a class using a macro defined in the class from main.cpp. I'm using jrowberg MPU6050 library if that matters.</p>

<p>main.cpp</p>

<pre><code>#include "gyro.h"
gyro gyro(Serial);
#define OUTPUT_READABLE_EULER

void setup(){
...
}
void loop(){
...
}
</code></pre>

<p>gyro.cpp</p>

<pre><code>  #include "gyro.h"
  #ifdef OUTPUT_READABLE_EULER
      // display Euler angles in degrees
      mpu.dmpGetQuaternion(&amp;q, fifoBuffer);
      mpu.dmpGetEuler(euler, &amp;q);
      serial_.print("euler\t");
      serial_.print(euler[0] * 180/M_PI);
      serial_.print("\t");
      serial_.print(euler[1] * 180/M_PI);
      serial_.print("\t");
      serial_.println(euler[2] * 180/M_PI);
  #endif
</code></pre>

<p>If I define <code>OUTPUT_READABLE_EULER</code> in <code>gyro.h</code>, it works. But I want to do it from main.cpp.</p>
 31105: <p>You cannot not, but also you should not try to define a macro in a cpp file and use it in another cpp file.</p>

<p>Instead, you have to define it in a h (header) file, which is included in both cpp files.</p>

<p>Why would you define it in <code>main.cpp</code> or <code>main.h</code> anyway if you don't use it in those files?</p>

<p>You have mainly three options:</p>

<ul>
<li>Define it in <code>gyro.h</code> so you include it in <code>gyro.cpp</code> where you use it. You can later use it in other files as well.</li>
<li>Define it in <code>gyro.cpp</code> so you can use it only in that file. This prevents the macro being used in other files (which can be safer).</li>
<li>Define it in a separate file, e.g. <code>euler.h</code> and include this header file everywhere you need it.</li>
</ul>

<p>See also Juraj's comments below.</p>
