Difference between compiler for Teensy3.5 and Mega2560?

Hi,
I have a project with 11 files. Several .cpp and .h files are in the same directory as the sketch .ino. Some of the .cpp files contain C code (no class definitions).
All that compiles well for a Mega2560 in the Arduino IDE 1.8.15 with the Teensy extensions.

Now I changed the code to run on a Teensy 3.5 and cannot compile it.
Example:
One of the C files (with .cpp extension) contains the function dispWindData() which calls a function draw_winddata() in the same file.

File EPD_grapp.cpp:

#include "EPD_grapp.h"

void draw_winddata(word idx1, word idx2, char* warntext) {
...
}

void dispWindData(boolean newaxes, char* warntext) {
...
  draw_winddata(rbuf0,rbuf_idx, wtext);
...

For this simple code structure I get a compiler error (and a lot more):

.../TestC-Cpp/EPD_grapp.cpp:593: undefined reference to `draw_winddata(unsigned int, unsigned int, char*)'

The according header file, EPD_grapp., contains both function declarations. And for a Mega2560 it compiles but not for a Teensy3.5.

I guess it is a problem with including C code into C++ code which works differently for a Mega2560 and a Teensy3.5. Looking around for tips and solutions I found discussions about using
exter "C" {...}
But I don't know how to use it.

A test with sourrounding the include statement with extern "C" {..} did not work.

File EPD_grapp.cpp:

extern "C" {
#include "EPD_grapp.h"
}

void draw_winddata(word idx1, word idx2, char* warntext) {
...
}

void dispWindData(boolean newaxes, char* warntext) {
...
  draw_winddata(rbuf0,rbuf_idx, wtext);
...

Here I get a bulk of errors of type

c:\zusprogs\arduino\arduino-1.8.15\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1\type_traits:68:3: error: template with C linkage
   template<typename _Tp, _Tp __v>
   ^

Tips and of course solutions are very welcome :pensive:

Put together a smaller, complete example (than your 11-file project) that demonstrates the problem and post it here.

What are the exact data types of rbuf0, rbuf_idx, and wtext?

This means that this is not C, but C++ (C has no templates).

What it means is that when @SupArdu randomly threw in the exter "C" { directive, it caused the resulting code to be compiled as 'C'. But, since the code contains templates (obviously in parts of the code that weren't posted), compiling a 'C' is a no-go.

Indeed, the extern "C" directive is likely to be the cause of these errors.

But not the errors OP posted before adding the exern "C"{.
My first guess is a data type mismatch in the function call.

That could very well be. I hope OP responds to your request (and posts the full error message).

Hi, again.
I reduced the code to 4 files and also reduced the content of the files. The code now is not meaningful for the originally intended purpose but it shows the effects of compilation.

epd.h (5.6 KB)
EPD_grapp.cpp (11.1 KB)
EPD_grapp.h (2.7 KB)
TestC-Cpp.ino (673 Bytes)
All 4 files are contained in my sketch folder TestC-Cpp.
Compilation without extern "C" {..} results in these errors:

Arduino: 1.8.15 (Windows 10), TD: 1.54, Board: "Teensy 3.5, Serial, 120 MHz, Faster, German"


C:\Users\Klaus\AppData\Local\Temp\arduino_build_222034\sketch\EPD_grapp.cpp.o: In function `draw_axes(unsigned short, unsigned short)':

H:\Arduino\examples\GSM_Shield_gboard_pro\TestC-Cpp/EPD_grapp.cpp:204: undefined reference to `epd_clear()'

H:\Arduino\examples\GSM_Shield_gboard_pro\TestC-Cpp/EPD_grapp.cpp:205: undefined reference to `epd_draw_line(int, int, int, int)'

H:\Arduino\examples\GSM_Shield_gboard_pro\TestC-Cpp/EPD_grapp.cpp:224: undefined reference to `epd_set_en_font(unsigned char)'

H:\Arduino\examples\GSM_Shield_gboard_pro\TestC-Cpp/EPD_grapp.cpp:241: undefined reference to `epd_disp_string(void const*, int, int)'

H:\Arduino\examples\GSM_Shield_gboard_pro\TestC-Cpp/EPD_grapp.cpp:246: undefined reference to `epd_set_en_font(unsigned char)'

H:\Arduino\examples\GSM_Shield_gboard_pro\TestC-Cpp/EPD_grapp.cpp:247: undefined reference to `epd_disp_string(void const*, int, int)'

H:\Arduino\examples\GSM_Shield_gboard_pro\TestC-Cpp/EPD_grapp.cpp:239: undefined reference to `epd_disp_string(void const*, int, int)'

C:\Users\Klaus\AppData\Local\Temp\arduino_build_222034\sketch\EPD_grapp.cpp.o: In function `dispWindData(bool, char*)':

H:\Arduino\examples\GSM_Shield_gboard_pro\TestC-Cpp/EPD_grapp.cpp:356: undefined reference to `draw_winddata(unsigned int, unsigned int, char*)'

H:\Arduino\examples\GSM_Shield_gboard_pro\TestC-Cpp/EPD_grapp.cpp:359: undefined reference to `draw_winddata(unsigned int, unsigned int, char*)'

collect2.exe: error: ld returned 1 exit status

Error compiling for board Teensy 3.5.



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.


For compilation with extern "C" I made a small change in EPD_grapp.cpp:

/*  Grafik-Funktionen zur Darstellung des Plots der Winddaten.
    ...     */

#include "epd.h"
extern "C" {
#include "EPD_grapp.h"
}

volatile  uint8_t prog_state;

...

Now the errors are too much for this post. Therefore here a part as copy and the full error list as attachment.

In file included from C:\ZusProgs\Arduino\arduino-1.8.15\hardware\teensy\avr\cores\teensy3/wiring.h:45:0,
                 from C:\ZusProgs\Arduino\arduino-1.8.15\hardware\teensy\avr\cores\teensy3/WProgram.h:45,
                 from C:\Users\Klaus\AppData\Local\Temp\arduino_build_222034/pch/Arduino.h:6,
                 from H:\Arduino\examples\GSM_Shield_gboard_pro\TestC-Cpp\EPD_grapp.h:6,
                 from H:\Arduino\examples\GSM_Shield_gboard_pro\TestC-Cpp\EPD_grapp.cpp:10:
c:\zusprogs\arduino\arduino-1.8.15\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1\type_traits:68:3: error: template with C linkage
   template<typename _Tp, _Tp __v>
   ^
c:\zusprogs\arduino\arduino-1.8.15\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1\type_traits:83:3: error: template with C linkage
   template<typename _Tp, _Tp __v>
   ^
c:\zusprogs\arduino\arduino-1.8.15\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1\type_traits:92:3: error: template with C linkage
   template<bool __v>
   ^
c:\zusprogs\arduino\arduino-1.8.15\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1\type_traits:97:3: error: template with C linkage
   template<bool, typename, typename>
   ^
c:\zusprogs\arduino\arduino-1.8.15\hardware\tools\arm\arm-none-eabi\include\c++\5.4.1\type_traits:100:3: error: template with C linkage
   template<typename...>
   ^
... --------------------------------------------
some further error types:
In file included from C:\ZusProgs\Arduino\arduino-1.8.15\hardware\teensy\avr\cores\teensy3/Print.h:38:0,
                 from C:\ZusProgs\Arduino\arduino-1.8.15\hardware\teensy\avr\cores\teensy3/Stream.h:24,
                 from C:\ZusProgs\Arduino\arduino-1.8.15\hardware\teensy\avr\cores\teensy3/HardwareSerial.h:274,
                 from C:\ZusProgs\Arduino\arduino-1.8.15\hardware\teensy\avr\cores\teensy3/WProgram.h:46,
                 from C:\Users\Klaus\AppData\Local\Temp\arduino_build_222034/pch/Arduino.h:6,
                 from H:\Arduino\examples\GSM_Shield_gboard_pro\TestC-Cpp\EPD_grapp.h:6,
                 from H:\Arduino\examples\GSM_Shield_gboard_pro\TestC-Cpp\EPD_grapp.cpp:10:
C:\ZusProgs\Arduino\arduino-1.8.15\hardware\teensy\avr\cores\teensy3/WString.h:117:83: error: conflicting declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, const char*)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr);
                                                                                   ^
C:\ZusProgs\Arduino\arduino-1.8.15\hardware\teensy\avr\cores\teensy3/WString.h:116:27: note: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, const String&)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs);
                           ^
C:\ZusProgs\Arduino\arduino-1.8.15\hardware\teensy\avr\cores\teensy3/WString.h:118:100: error: conflicting declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, const __FlashStringHelper*)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHelper *pgmstr);
                                                                                                    ^
C:\ZusProgs\Arduino\arduino-1.8.15\hardware\teensy\avr\cores\teensy3/WString.h:117:27: note: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, const char*)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr);
                           ^
C:\ZusProgs\Arduino\arduino-1.8.15\hardware\teensy\avr\cores\teensy3/WString.h:118:100: error: conflicting declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, const __FlashStringHelper*)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHelper *pgmstr);
                                                                                                    ^
C:\ZusProgs\Arduino\arduino-1.8.15\hardware\teensy\avr\cores\teensy3/WString.h:116:27: note: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, const String&)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs);
                           ^
C:\ZusProgs\Arduino\arduino-1.8.15\hardware\teensy\avr\cores\teensy3/WString.h:119:73: error: conflicting declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, char)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, char c);
                                                                         ^
C:\ZusProgs\Arduino\arduino-1.8.15\hardware\teensy\avr\cores\teensy3/WString.h:118:27: note: previous declaration 'StringSumHelper& operator+(const StringSumHelper&, const __FlashStringHelper*)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHelper *pgmstr);
                           ^
C:\ZusProgs\Arduino\arduino-1.8.15\hardware\teensy\avr\cores\teensy3/WString.h:119:73: error: conflicting declaration of C function 'StringSumHelper& operator+(const StringSumHelper&, char)'
  friend StringSumHelper & operator + (const StringSumHelper &lhs, char c);
 ...

I am totally confused with these errors.
What happens?
erros-externC.txt (126.3 KB)

Please answer my question about date types.

the data types are correct, see my detailed post #11.
They are
word rbuf_idx;
word rbuf0=0;

Where is type 'word' defined? Could the definition be different between the two compilers?

Try using 'uint16_t' in place of 'word' and see if that helps.

In EPD_grapp.h the following prototypes do not match the implementation in EPD_grapp.cpp:

  • storeWDat
  • setUnit_mps
  • dispWindData

You have not included epd.cpp or epd.c, so no further testing can be done.

You may want to check the compiler options, I know some boards have differences in the fpermissive option, causing warning on most arduino boards while the same thing causes an error on boards such as the esp8266.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.