C and C++ compilers make your code better when they compile it! This is great, but when we are trying to debug our code we don't want anything to change it.

If you try to use the debugger and you see that it doesn't move from one line to the next as you would expect, this is because you have compiler optimizations turned on.

to turn them off, right click on the ArduinoCore project in the Solution Explorer pane, and click properties.

Then under Toolchain, go to the ARM/GNU C Compiler heading and click Optimization. Set Optimization Level to None (-O0).

Then do the same thing under the ARM/GNU C++ Compiler heading.

Then save your project.

Now, repeat the above steps to turn off compiler optimizations for the other project (whatever you have named your sketch) in the solution explorer.

There should be two projects in the Solution Explorer pane. ArduinoCore, and whatever you have named your sketch. Make sure you have done the above steps to turn off compiler optimizations on both projects in the solution explorer pane.

Correcting Paths to Necessary Files

Current versions of Arduino have changed the location of the CMSIS core files that are necessary to compile projects.

We can fix these paths by going back to the Properties pane (by right clicking on the project in Solution Explorer and selecting Properties as we did before) and under ARM/GNU C Compiler select Directories and add the new path to the CMSIS core files to the Include Paths section.

This can be done by clicking the green plus button, and then finding the folder by clicking the ... button in the window that pops up.

Leave the Relative Path box checked.

The current location of the CMSIS core as of the writing of this guide is:


Then select the path you just added in the list and click the yellow up arrow icon to move it to the top of the list.

Now repeat those same steps in the Directories pane under the ARM/GNU C++ Compiler section. 

Do these steps for both projects in the Solution Explorer pane.

Make sure you have done the steps under the "Correcting Paths To Necessary Files" heading for both projects in the Solution Explorer pane.

Fixing Some Core Files

If you try to debug your sketch now, it may warn of an "undefined referenced to `vtable for HardwareSerial'"

To fix this, open the includes/core/HardwareSerial.h file under the ArduinoCore project.

Scroll down to the class definition around line 67 and replace the class declaration with the following code:

class HardwareSerial : public Stream
	HardwareSerial() {};
	virtual ~HardwareSerial() {};
    virtual void begin(unsigned long) {};
    virtual void begin(unsigned long baudrate, uint16_t config) {};
    virtual void end() {};
    virtual int available(void) = 0;
    virtual int peek(void) = 0;
    virtual int read(void) = 0;
    virtual void flush(void) = 0;
    virtual size_t write(uint8_t) = 0;
    using Print::write; // pull in write(str) and write(buf, size) from Print
    virtual operator bool() = 0;

Your file should look like this:

Once this is done, you should be able to compile and debug your sketch!

This guide was first published on Feb 25, 2016. It was last updated on Jun 08, 2017.

This page (Paths and Optimizations) was last updated on Jun 08, 2017.

Text editor powered by tinymce.