Go Down

Topic: ARDUINO 101 - multiple source files  (Read 147 times) previous topic - next topic

konobarskizidar

Hi People,

short question: i want to separate my .ino file into multiple source files for the sake of the better code overview.

I have menaged to separate global variables and functions that doesnt depend on any external library.
When i want to include for example Wire, Serial or Magwick in header file of his own source file i encounter difficulties by creating an object in same soruce file.

Header
Code: [Select]

//senzoriFun.h

#ifndef GLOBAL_H
#include "global.h"
#endif

#ifndef MADGWICKAHRS_H
#include <MadgwickAHRS.h>
#endif

#ifndef CURIEIMU_H
#include <CurieIMU.h>
#endif

#ifdef __cplusplus
extern "C" {
#endif

void prikaz();

#ifdef __cplusplus
}
#endif



Source
Code: [Select]

//senzoriFun.c
#include "senzoriFun.h"

Madgwick filter; //creating object

void prikaz(){
}
 


common error messages refers to both library:   

error: unknown type name 'class'
error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token

for info: every source file.c and own header file.h is located in one folder with main.ino

Thanks in advance 


pert

When you encounter an error you'll see a button on the right side of the orange bar "Copy error messages". Click that button. Paste the error in a message here using code tags.

konobarskizidar

Following error message:

Code: [Select]

Arduino: 1.8.2 (Windows 10), Board: "Arduino/Genuino 101"

In file included from sketch\senzoriFun.h:7:0,

                 from sketch\senzoriFun.c:1:

C:\Users\Tibor\Documents\Arduino\libraries\Madgwick\src/MadgwickAHRS.h:23:1: error: unknown type name 'class'

 class Madgwick{

 ^

C:\Users\Tibor\Documents\Arduino\libraries\Madgwick\src/MadgwickAHRS.h:23:15: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token

 class Madgwick{

               ^

In file included from C:\Users\Tibor\AppData\Local\Arduino15\packages\Intel\hardware\arc32\2.0.2\libraries\CurieIMU\src/CurieIMU.h:25:0,

                 from sketch\senzoriFun.h:11,

                 from sketch\senzoriFun.c:1:

C:\Users\Tibor\AppData\Local\Arduino15\packages\Intel\hardware\arc32\2.0.2\libraries\CurieIMU\src/BMI160.h:478:1: error: unknown type name 'class'

 class BMI160Class {

 ^

C:\Users\Tibor\AppData\Local\Arduino15\packages\Intel\hardware\arc32\2.0.2\libraries\CurieIMU\src/BMI160.h:478:19: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token

 class BMI160Class {

                   ^

In file included from sketch\senzoriFun.h:11:0,

                 from sketch\senzoriFun.c:1:

C:\Users\Tibor\AppData\Local\Arduino15\packages\Intel\hardware\arc32\2.0.2\libraries\CurieIMU\src/CurieIMU.h:93:1: error: unknown type name 'class'

 class CurieIMUClass : public BMI160Class {

 ^

C:\Users\Tibor\AppData\Local\Arduino15\packages\Intel\hardware\arc32\2.0.2\libraries\CurieIMU\src/CurieIMU.h:93:21: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token

 class CurieIMUClass : public BMI160Class {

                     ^

C:\Users\Tibor\AppData\Local\Arduino15\packages\Intel\hardware\arc32\2.0.2\libraries\CurieIMU\src/CurieIMU.h:250:1: error: unknown type name 'CurieIMUClass'

 extern CurieIMUClass CurieIMU;

 ^

senzoriFun.c:3: error: unknown type name 'Madgwick'

 Madgwick filter; //creating object

 ^

exit status 1
unknown type name 'Madgwick'

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



Tnx!

pert

It seems like the library is being interpreted as C (which doesn't support classes) instead of C++ (which does). Try renaming senzoriFun.c to senzoriFun.cpp. Most of the Arduino library code you will find is C++.

konobarskizidar

Thanks very much!

That solved me a Problem

Best regards / Mit freundlcihen Grüßen / Sve najbolje !

Go Up