Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVR-C error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token [closed]

I'm currently attempting to take the code library written for the Arduino USB Host shield and decouple it from the Arduino core libraries so that I can use the code in a non-Arduino microcontroller project.

From looking at the code, there aren't a lot of hard dependencies on the Arduino code base, but I'm running into some weird errors that are probably due to the differences between the Arduino build system and the LUFA build system. Specifically, I'm getting the following error in about 75% of the header files, several dozen times each:

error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token

Sometimes, the error indicates different tokens in the error, but it's still the same error. I've found a lot of similar issues in various forums and on Stack Overflow, but the solution tends to be different every time.

To be clear, this code compiles 100% fine within the Arduino build system, but these errors occur when I try to build directly with WinAVR, using the LUFA template makefiles. From looking through the code, I have determined that I needed to #define a few values, such as -DARDUINO=102 (or at least some value >=100, but the version of the Arduino IDE I'm using is 1.0.2, so I figured that was a good value to use).

So I suppose I'm looking for someone familiar with the Arduino build system to help me figure out what I'm missing. The full code library can be found here, but for the sake of providing a simple example that demonstrates the problem without including the entire code library, here's printhex.h:

#if !defined(__PRINTHEX_H__)
#define __PRINTHEX_H__

#if defined(ARDUINO) && ARDUINO >=100
#include "Arduino.h"
#else
#include <WProgram.h>
#endif

template <class T>
void PrintHex(T val)
{
    T mask = (((T)1) << (((sizeof(T) << 1) - 1) << 2));

    while (mask > 1)
    {
        if (val < mask)
            Serial.print("0");

        mask >>= 4;
    }
    Serial.print((T)val, HEX);
}

template <class T>
void PrintHex2(Print *prn, T val)
{
    T mask = (((T)1) << (((sizeof(T) << 1) - 1) << 2));

    while (mask > 1)
    {
        if (val < mask)
            prn->print("0");

        mask >>= 4;
    }
    prn->print((T)val, HEX);
}

template <class T>
void PrintBin(T val)
{
    for (T mask = (((T)1) << (sizeof(T) << 3)-1); mask; mask>>=1)
        if (val & mask)
            Serial.print("1");
        else
            Serial.print("0");
}

#endif

I should note that I do have Arduino.h copied to my include path, and that if I include Arduino.h into my main .c file, it compiles fine, so the issue isn't there. Including printhex.h, however, produces the following:

In file included from MIDI.c:38:
Lib/HostShield/printhex.h:26: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
Lib/HostShield/printhex.h:41: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
Lib/HostShield/printhex.h:56: error: expected '=', ',', ';', 'asm' or '__attribute__' before '<' token
make: *** [MIDI.o] Error 1

Lines 26, 41, and 56 are the 3 instances of the following:

template <class T>

I'm stumped. How can I solve this problem?

like image 990
qwertymodo Avatar asked Feb 15 '13 19:02

qwertymodo


1 Answers

You're trying to compile C++ code as C. You can (usually) do the reverse, but you need to rewrite this as plain C or use a C++ compiler (avr-g++, it appears). Changing your files to .cpp may tell the build system to use a C++ compiler automatically.

like image 100
Kevin Avatar answered Oct 26 '22 06:10

Kevin