Skip to content

Prototype Generation With Typedef'd Types #8050

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

Closed
zachdeibert opened this issue Oct 2, 2018 · 1 comment
Closed

Prototype Generation With Typedef'd Types #8050

zachdeibert opened this issue Oct 2, 2018 · 1 comment

Comments

@zachdeibert
Copy link

When the Arduino IDE attempts to generate the prototypes for a function where the types that are a part of that prototype are defined in a header file, the IDE does not always include the header file defining the type before the generated prototype is emitted to the file that is passed into G++.

Code is available here

Build Output:

/home/zach/software/arduino-1.8.5/arduino-builder -dump-prefs -logger=machine -hardware /home/zach/software/arduino-1.8.5/hardware -tools /home/zach/software/arduino-1.8.5/tools-builder -tools /home/zach/software/arduino-1.8.5/hardware/tools/avr -built-in-libraries /home/zach/software/arduino-1.8.5/libraries -libraries /home/zach/Arduino/libraries -fqbn=arduino:avr:nano:cpu=atmega328 -ide-version=10805 -build-path /tmp/arduino_build_613863 -warnings=all -build-cache /tmp/arduino_cache_167137 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avrdude.path=/home/zach/software/arduino-1.8.5/hardware/tools/avr -prefs=runtime.tools.arduinoOTA.path=/home/zach/software/arduino-1.8.5/hardware/tools/avr -prefs=runtime.tools.avr-gcc.path=/home/zach/software/arduino-1.8.5/hardware/tools/avr -verbose /code/github.com/zachdeibert/arduino-ide-prototype-bug/arduino-ide-prototype-bug.ino
/home/zach/software/arduino-1.8.5/arduino-builder -compile -logger=machine -hardware /home/zach/software/arduino-1.8.5/hardware -tools /home/zach/software/arduino-1.8.5/tools-builder -tools /home/zach/software/arduino-1.8.5/hardware/tools/avr -built-in-libraries /home/zach/software/arduino-1.8.5/libraries -libraries /home/zach/Arduino/libraries -fqbn=arduino:avr:nano:cpu=atmega328 -ide-version=10805 -build-path /tmp/arduino_build_613863 -warnings=all -build-cache /tmp/arduino_cache_167137 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avrdude.path=/home/zach/software/arduino-1.8.5/hardware/tools/avr -prefs=runtime.tools.arduinoOTA.path=/home/zach/software/arduino-1.8.5/hardware/tools/avr -prefs=runtime.tools.avr-gcc.path=/home/zach/software/arduino-1.8.5/hardware/tools/avr -verbose /code/github.com/zachdeibert/arduino-ide-prototype-bug/arduino-ide-prototype-bug.ino
Using board 'nano' from platform in folder: /home/zach/software/arduino-1.8.5/hardware/arduino/avr
Using core 'arduino' from platform in folder: /home/zach/software/arduino-1.8.5/hardware/arduino/avr
Detecting libraries used...
"/home/zach/software/arduino-1.8.5/hardware/tools/avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR   "-I/home/zach/software/arduino-1.8.5/hardware/arduino/avr/cores/arduino" "-I/home/zach/software/arduino-1.8.5/hardware/arduino/avr/variants/eightanaloginputs" "/tmp/arduino_build_613863/sketch/arduino-ide-prototype-bug.ino.cpp" -o "/dev/null"
Generating function prototypes...
"/home/zach/software/arduino-1.8.5/hardware/tools/avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics  -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR   "-I/home/zach/software/arduino-1.8.5/hardware/arduino/avr/cores/arduino" "-I/home/zach/software/arduino-1.8.5/hardware/arduino/avr/variants/eightanaloginputs" "/tmp/arduino_build_613863/sketch/arduino-ide-prototype-bug.ino.cpp" -o "/tmp/arduino_build_613863/preproc/ctags_target_for_gcc_minus_e.cpp"
"/home/zach/software/arduino-1.8.5/tools-builder/ctags/5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "/tmp/arduino_build_613863/preproc/ctags_target_for_gcc_minus_e.cpp"
Compiling sketch...
"/home/zach/software/arduino-1.8.5/hardware/tools/avr/bin/avr-g++" -c -g -Os -Wall -Wextra -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10805 -DARDUINO_AVR_NANO -DARDUINO_ARCH_AVR   "-I/home/zach/software/arduino-1.8.5/hardware/arduino/avr/cores/arduino" "-I/home/zach/software/arduino-1.8.5/hardware/arduino/avr/variants/eightanaloginputs" "/tmp/arduino_build_613863/sketch/arduino-ide-prototype-bug.ino.cpp" -o "/tmp/arduino_build_613863/sketch/arduino-ide-prototype-bug.ino.cpp.o"
add:3: error: 'number_t' does not name a type
 number_t add(number_t a, number_t b) {
 ^
/code/github.com/zachdeibert/arduino-ide-prototype-bug/arduino-ide-prototype-bug.ino: In function 'void loop()':
arduino-ide-prototype-bug:7: error: 'add' was not declared in this scope
   Serial.println(add(2, 2));
                          ^
exit status 1
'number_t' does not name a type

C++ file generation:

#include <Arduino.h>
#line 1 "/code/github.com/zachdeibert/arduino-ide-prototype-bug/arduino-ide-prototype-bug.ino"
#line 1 "/code/github.com/zachdeibert/arduino-ide-prototype-bug/arduino-ide-prototype-bug.ino"
#line 1 "/code/github.com/zachdeibert/arduino-ide-prototype-bug/arduino-ide-prototype-bug.ino"
void setup();
#line 5 "/code/github.com/zachdeibert/arduino-ide-prototype-bug/arduino-ide-prototype-bug.ino"
void loop();
#line 3 "/code/github.com/zachdeibert/arduino-ide-prototype-bug/add.ino"
number_t add(number_t a, number_t b);
#line 1 "/code/github.com/zachdeibert/arduino-ide-prototype-bug/arduino-ide-prototype-bug.ino"
void setup() {
  Serial.begin(115200);
}

void loop() {
  Serial.print("2 + 2 = ");
  Serial.println(add(2, 2));
  delay(1000);
}


#line 1 "/code/github.com/zachdeibert/arduino-ide-prototype-bug/add.ino"
#include "number.h"

number_t add(number_t a, number_t b) {
  return a + b;
}

Workaround: Including all header files into the main INO fixes the problem, but that should not be required.

@facchinm
Copy link
Member

facchinm commented Oct 3, 2018

Hi @zachdeibert ,
this is a known limitation of the prototype generator; we don't move includes around so main sketch should include all needed headers. Wound you mind moving the issue to https://github.com/arduino/arduino-builder as a feature request? Thanks!

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

No branches or pull requests

2 participants