I am writing my own code for the Arduino Uno. I compile my code with AVR-gcc, and then upload it with AVRdude. I am not using the Arduino software, but I do have it installed and working on my PC. I want to include some of the Arduino libraries in my project, like Wire.h for example.

I realise that I could either copy the source file to my current working directory or include the entire path, like: #include "/usr/share/arduino/libraries/Wire/Wire.h" but the issue with that is Wire.h includes Stream.h which includes Print.h which includes...you get the idea. These different libraries are not kept in the same place either. I would have to hunt up and down chains of files, copy them and then use them locally. This does not seem like a good option to me.

Including them like I normally would using the IDE doesn't work at all, which is not surprising.

So, how can I use these libraries in my project without all the pain of finding them manually?

  • the 'core' is independent from IDE github.com/arduino/ArduinoCore-avr
    – Juraj
    Commented Jul 26, 2018 at 7:29
  • @Juraj: I should have clarified, I am writing my own code, compiling with AVR-gcc and uploading using AVRdude. I am not using the Arduino software at all.
    – user37286
    Commented Jul 26, 2018 at 7:36
  • 1
    Juraj's comment is still valid. You can include and compile the Arduino AVR Core without ever having to install or open the Arduino IDE. These are just C/C++ header and implementation files. Just delete the ones you don't need, and add it to your include path. Finally, just add the folder to your build system as an external library, and link it against your final executable. If you don't want to add all the extra code for Print and Stream, you'll have to modify or rewrite the Wire library yourself.
    – tttapa
    Commented Jul 26, 2018 at 8:30
  • @Jǝssǝ You could have a look at the Cosa command line build (github.com/mikaelpatel/Cosa/tree/master/build). It is a modification of Arduino-Makefile with a few shell script wrappers to make it easy to use (e.g. do not need to write makefiles). It supports build, upload, serial monitor, etc. Commented Jul 26, 2018 at 13:37

1 Answer 1


Since you will end up using a significant portion of the Arduino core library, the easiest path is to accept the idea that you are now writing “Arduino sketches” rather than plain C++ code. Don't resist, be assimilated, fire the IDE and write setup() and loop(). ;-)

Once you have something working, the next step is to get rid of the IDE, which is admittedly not very nice. A couple of ways to do that:

  • Use Arduino Builder, the command-line tool for building Arduino sketches. The internals of this are the same as for the Arduino IDE, but it works on the command line.
  • Use a Makefile, like Sudar Muthu's Arduino-Makefile. This is a generic Makefile for building Arduino programs. It is not 100% compatible with the IDE or Aduino builder, as it does not add function declarations for you, but it may suit you better if you are used to a more standard toolchain (it's just make + avr-gcc + avrdude).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.