I need to convert Arduino code to avr-gcc code. This is code:

#include <Servo.h> 

Servo myservo; 

void setup() {

void loop() { 

I use Arduino Mega.

  • 4
    I'm voting to close this question as off-topic because this is not a "gimme tha codez" site.
    – Majenko
    Jan 13, 2017 at 13:38
  • Possible duplicate of Will a .ino Arduino Sketch compile directly on GCC-AVR?
    – sa_leinad
    Jan 14, 2017 at 3:57
  • 1
    You didn't actually ask a question, you might have asked: "how can I re-implement the servo library in avr-gcc", but that will require quite some effort and a little knowledge from your side.
    – aaa
    Jan 14, 2017 at 9:22

1 Answer 1


Try this:

#include <Servo.h>

extern "C" void init(void);

Servo myservo;

int main()
    for (;;) {

Note that this still needs the Arduino core library, as the Servo library depends on it, which means all this is an exercise in futility. If you are using the Arduino core, the simplest thing is to use it the Arduino way. If you do not want to use Arduino core, then you will have to partially re-implement the Servo library.

  • @user29971: oops, forgot an include, fixed. Do not forget to add all the relevant -I, -L and -l options to the compile command. Jan 13, 2017 at 14:02
  • compiler code in avr-gcc comand line in linux no include Arduino.h include avr/io.h. thanks Edgar Bonet
    – user29971
    Jan 13, 2017 at 14:07
  • i use standard library and registers.
    – user29971
    Jan 13, 2017 at 14:15
  • @user29971: If you do not want to #include <Arduino.h>, you can just declare init() yourself, see amended answer. Jan 14, 2017 at 8:05

Not the answer you're looking for? Browse other questions tagged or ask your own question.