Platformio Error does not name a type - platformio

I have very simply code:
main.cpp
#include <Arduino.h>
#include "config.h"
Config c;
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
config.h
#ifndef Config_h
#define Config_h
class Config{
public:
Config(){};
};
#endif
config.cpp
#include "config.h"
When I try to build project, I got the below error:
src\main.cpp:4:1: error: 'Config' does not name a type
What is wrong here?

I have found solution config.h => myconfig.h

Related

FreeRTOS Project Setup with error: expected ')' before string constant

I am starting a new project on a STM32L476 Nucleo board and planned to use FreeRTOS.
My initial project structure:
main.c
#include "project.h"
int main(void)
{
/* Configure the system clock */
Clock_Config();
/* Configure IOs */
GPIO_Config();
/* FreeRTOS Stuff */
NVIC_SetPriorityGrouping(3);
vTaskStartScheduler();
/* Should never get here! */
while (1){}
}
project.h
#ifndef PROJECT_H_
#define PROJECT_H_
/* MPU Files */
#include "stm32l4xx.h"
/* Project Files */
#include "gpio.h"
#include "clock.h"
/* FreeRTOS */
#include "FreeRTOS.h"
#include "queue.h"
#include "task.h"
#define TASKPRIO_STD ( tskIDLE_PRIORITY + 1 )
#define TICK_TASK_PERIOD_MS pdMS_TO_TICKS( 500 )
#endif /* PROJECT_H_ */
project.c
#include "project.h"
static void vSerialTask( void * pvParameters );
xTaskCreate( vSerialTask, "I2C", configMINIMAL_STACK_SIZE, NULL, TASKPRIO_STD, NULL);
static void vSerialTask( void *pvParameters ){
for( ;; )
{
}
}
I get a syntax error with this structure in xTaskCreate line: expected ')' before string constant
If I move xTaskCreate to my main.c and leave the task itself in my project.c (also have to delete static in this case) my project compiles successfully.
What is the problem here? I already saw working projects where xTaskCreate is not done within main.c so can't imagine this is the real problem?
You can't call the function outside another function and it is exactly what you try to do.
You can only call functions from another functions. The first function executed is main

unknown type name on defining object of another class from same file in C++

In my one c++ file named "two_elements.cpp", I am defining two classes within same file, and the code goes like below:
#include <iostream>
#include <cstream>
class A{
public:
void methodA(){
//do something
}
};
class B{
public:
A a_obj;
a_obj.methodA();
};
This throws the following error:
error: unknown type name 'a_obj'
I folowed the following stack overflow links comprehensively, but could not find a work around:
Unknown type name class
unknown type name 'class'
C++ - 2 classes 1 file
Please note most of these questions had classes in the individual header files.
I found the solution:
#include <iostream>
#include <cstream>
class A{
public:
void methodA(){
//do something
}
};
class B{
public:
A a_obj;
B(){
a_obj.methodA();
}
};
An instance needs to be called inside a constructor or a function in c++.

How to add an header file in a C project on Eclipse?

I real need help over here, I have to do this ASCIITwitter project for an university's exam and I'm stucked with this problem:
I have to add a header file and a source file on my project of course, so first I tried some easy code to see if I'm capable to do this.
Just a program to do some square operations:
There's my code:
Twitter.h
#ifndef TWITTER_H_
#define TWITTER_H_
int square(int);
#endif /* TWITTER_H_ */
Twitter.c
#include "Twitter.h"
int square(int x)
{
return x*x;
}
main.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "Twitter.h"
int main(void)
{
int y;
y=square(5);
printf("%d\n",y);
system("PAUSE");
}
But it give to me "undefined reference to 'square' and I really don't know how to fix this. I've tried searching on internet, but I'm working on windows, I don't have any makefile, I just want to make this work. Please help me.

boost thread+signals: mem_fn error, invalid use of non-static member function

I am trying to get acquainted with boost thread and signals. I have therefore implemented this very simple code consisting of a class (Class1) implementing a thread. I'd like this class to provide services as result of signals reception. To this end I have just started to exploit the signal boost library but I am getting this error:
/home/andrea/libs/boost_1_50_0/boost/bind/mem_fn.hpp:359:22: error: invalid use of non-static member function
when I try to compile it in the Eclipse environment with gcc. Is there anything wrong with the singleton or is the binding to the instance method?
Here is Class1.cpp
#include "Class1.hpp"
#include <boost/thread.hpp>
#include <boost/date_time.hpp>
#include "Package1.hpp"
Class1::Class1(){
boost::thread thread(boost::bind(&Class1::classifierBehavior,this));
};
void Class1::classifierBehavior(){
service.run();
Package1Signals::getInstance()->signal1.connect(boost::bind(&Class1::method1, boost::ref(*this)));
};
void Class1::method1(Signal1 signal1){}
And Package1.hpp
#ifndef PACKAGE1_HEADER
#define PACKAGE1_HEADER
#include <boost/signal.hpp>
struct Signal1{
int foo;
};
class Package1Signals{
private:
Package1Signals();
static Package1Signals * instance;
public:
boost::signal<void (Signal1)> signal1;
static Package1Signals * getInstance(){
if(!instance){
instance = new Package1Signals();
}
return instance;
};
};
#endif
Your binder should have 1 argument:
boost::bind(&Class1::methpod1, boost::ref(*this), _1)

Eclipse undefined reference

I'm using Eclipse and MinGW. I've got undefined reference to error to all that I write in h files, that I do include in cpp-file where main located. I create an empty project, and the same thing again (
main.cpp
#include <iostream>
#include "Stack.h"
using namespace std;
int main(){
Stack<int> stack(10);
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
return 0;
}
stack.h
#ifndef STACK_H_
#define STACK_H_
template <class T>
class Stack{
private:
struct StackEl;
StackEl *top;
public:
Stack();
Stack(T el);
~Stack();
void Push(const T& el);
T Pop();
};
#endif /* STACK_H_ */
and stack.cpp inplements everything from stack.h
If I include not h-file, but cpp - all works. Help please!
I've got following errors
D:/Workspacee/Stack2/Debug/../src/Stack2.cpp:16: undefined reference to `Stack<int>::Stack(int)'
D:/Workspacee/Stack2/Debug/../src/Stack2.cpp:18: undefined reference to `Stack<int>::~Stack()'
D:/Workspacee/Stack2/Debug/../src/Stack2.cpp:18: undefined reference to `Stack<int>::~Stack()'
This is a linker error. I'm no Eclipse expert, but you have to tell it somehow to add Stack.o to the linking command.
If you include Stack.cpp instead of Stack.h, the implementations from the cpp-file get included into main.cpp by the preprocessor before compilation, so the linking stage has no unresolved references to outside functions.
My bad, that is becouse templates! When you use template, all code, including realization of functions, must be in header-file, or you have to write prototypes for every type you are going to use you template-functions with. I've forgot about that working with templates is not the same as with usual function :(