Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leonardo: conflicting declaration 'HardwareSerial Serial' #6

Open
GoogleCodeExporter opened this issue May 5, 2015 · 4 comments
Open

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. Create empty arduino project
2. configure makefile to arduino leonardo:

# Arduino Leonardp
ARDUINO_MODEL = atmega32u4
ARDUINO_PROGRAMMER = arduino
ARDUINO_PINS_DIR = ${ARDUINO_BASE_DIR}/hardware/arduino/variants/leonardo

3. build project

What is the expected output? What do you see instead?

expected: a successful build. Instead, I get this:

"C:/Downloads/arduino-1.0.6/hardware/tools/avr/utils/bin/make" -f 
nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make[1]: Entering directory `C:/Arduino-Workspace/Test3'
"c:/Downloads/arduino-1.0.6/hardware/tools/avr/utils/bin/make"  -f 
nbproject/Makefile-Debug.mk dist/Debug/Arduino_1.0.6-Windows/test3.exe
make[2]: Entering directory `C:/Arduino-Workspace/Test3'
mkdir -p build/Debug/Arduino_1.0.6-Windows
rm -f "build/Debug/Arduino_1.0.6-Windows/main.o.d"
avr-g++ -c -g -Os -Wall -ffunction-sections -fdata-sections -mmcu=atmega32u4 
-DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=105 
-fno-exceptions   -c -g -I-c -g 
-Ic:/Downloads/arduino-1.0.6/hardware/arduino/cores/arduino 
-Ic:/Downloads/arduino-1.0.6/hardware/arduino/variants/leonardo 
-Ic:/Downloads/arduino-1.0.6/libraries/EEPROM -MMD -MP -MF 
"build/Debug/Arduino_1.0.6-Windows/main.o.d" -o 
build/Debug/Arduino_1.0.6-Windows/main.o main.cpp
main.cpp:3: error: conflicting declaration 'HardwareSerial Serial'
c:/Downloads/arduino-1.0.6/hardware/arduino/cores/arduino/USBAPI.h:47: error: 
'Serial' has a previous declaration as 'Serial_ Serial'
make[2]: *** [build/Debug/Arduino_1.0.6-Windows/main.o] Error 1
make[2]: Leaving directory `C:/Arduino-Workspace/Test3'
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory `C:/Arduino-Workspace/Test3'
make: *** [.build-impl] Error 2

What version of the product are you using? On what operating system?
NB8.0.1 + latest NB-Arduino Plugin + Arduino Leonardo

Please provide any additional information below.

If I comment the following line in main.cpp:

extern HardwareSerial Serial;

to

// extern HardwareSerial Serial;

compile works. But I need serial interface. Problem might be that leonardo has 
zwo serial interfaces? But no idea how to fix this issue.

Original issue reported on code.google.com by tuxedo0...@gmail.com on 31 Oct 2014 at 3:20

@GoogleCodeExporter
Copy link
Author

Eclipse Arduino PLugin seems to have a similar problem:

https://github.com/jantje/arduino-eclipse-plugin/issues/10

If I remove "extern HardwareSerial Serial;" fromt he code, NB tells me "extern 
HardwareSerial Serial;" but compile works. So seems that NB is not able to 
resolve the already declared "Serial" variable.

Question now is: how to tell NB that this variable is already declared? Looking 
over to the eclipse world, is might be, that the NB Arduino Plugin has the same 
indexing problem ...

Original comment by tuxedo0...@gmail.com on 3 Nov 2014 at 3:10

@GoogleCodeExporter
Copy link
Author

A small workaround, which is nit great, but works:

Instead of "extern" the "Serial" variable, redefine the already defines Serial:

//extern HardwareSerial Serial;
#define mySerial Serial

With help of that, there is no error shown in NB code editor and compile works. 
But one is not able to "lookup" what "mySerial" is (initially) etc.

Original comment by tuxedo0...@gmail.com on 3 Nov 2014 at 3:24

@GoogleCodeExporter
Copy link
Author

The workaround is not really applicable. Converting an application from 
ArduinoIDE to NB means: refacturing code ... 

I did another test:

switching from "Leonardo" back to "Uno".
removed the "extern ..." line and click "clean&build"... Build works, while NB 
editor shows my "unable to resolve identifier 'Serial'".

Conclusion:

The "extern ..." line is already a workaround for a broken index. Seems that 
something cannot be parsed correctly in editor view.

would be great if someone could confirm/react on this. I'm already searching 
the root of the bug, but did not find anything (I'm not yet familiar with 
NB+C/C++ ...).

regards,
 Alex

Original comment by tuxedo0...@gmail.com on 4 Nov 2014 at 1:39

@GoogleCodeExporter
Copy link
Author

Found the root of the issue, but yet no idea how to fix it:

HardwareSerial.h will "extern" the serial-variables based on flags:

UBRRH, UBRR0H, USBCON, UBRR1H, UBRR2H and UBRR3H

Those flags are set by device specific header files. For leonardo/micro 
(atmega32u4) this is iom32u4.h. And in this file, those flags are set.

This header file is included by io.h, which is included by Arduino.h ...

So all in all: device is set by make-file correctly (can be verified by setting 
a wrong avr device name/type). So arduino-h should include io.h, which shluld 
include avr type specific header file, i.e. iom32u4.h ...

The include-chain seems to be complete, but netbeans does not recognize it?!

Any ideas?

Original comment by tuxedo0...@gmail.com on 5 Nov 2014 at 11:10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant