# Error : Type expected '=', ',', ';', 'asm' or '\_\_attribute\_\_' before '{' token

**URL:** <https://forum.legato.io/t/error-type-expected-asm-or---attribute---before-token/2376>\
**Category:** Legato Linux distribution (Yocto project)\
**Created:** [March 6, 2017, 8:00am UTC](https://forum.legato.io/t/error-type-expected-asm-or---attribute---before-token/2376 "2017-03-06T08:00:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rups](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@rups](https://forum.legato.io/u/rups)\
**Post date:** [March 6, 2017, 8:00am UTC](https://forum.legato.io/t/error-type-expected-asm-or---attribute---before-token/2376/1 "2017-03-06T08:00:44Z")

</div>

Hi,

I have created one Legato application project and in that created one class  
while building the project, it gives error in ‘.h’ of class at declaration of class

error in class declaration on legato developer studio :  
Type expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘ **attribute** ’ before ‘{’ token

my ‘.h’ file code as below:

```
**#ifndef CFIRSTSAMPLECLASS_H_**
 **#define CFIRSTSAMPLECLASS_H_**

**class CfirstSampleclass**
 **{**
 **public:**
**CfirstSampleclass();**
**virtual ~CfirstSampleclass();**

**// additional variables and methods**

**};**

**#endif /* CFIRSTSAMPLECLASS_H_** */

```

Can any one tell me solution?

---

<div class="post-metadata">

**Author:** ![daav](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/daav/32/64_2.png) [@daav](https://forum.legato.io/u/daav)\
**Post date:** [March 6, 2017, 8:19am UTC](https://forum.legato.io/t/error-type-expected-asm-or---attribute---before-token/2376/2 "2017-03-06T08:19:34Z")

</div>

Hi @rups,

is your main source file named .c or .cpp?  
Depending on the extension, GCC will consider your code to be in C or in C++ language!  
My guess here is that your .h file is included by a .c file.

---

<div class="post-metadata">

**Author:** ![rups](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@rups](https://forum.legato.io/u/rups)\
**Post date:** [March 6, 2017, 9:10am UTC](https://forum.legato.io/t/error-type-expected-asm-or---attribute---before-token/2376/3 "2017-03-06T09:10:09Z")

</div>

yes, my main file is ‘.c’ . I have created project with legato application option.  
So, I can not generate C++ class in this project?  
Is there other way build it ?

---

<div class="post-metadata">

**Author:** ![rups](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@rups](https://forum.legato.io/u/rups)\
**Post date:** [March 6, 2017, 9:19am UTC](https://forum.legato.io/t/error-type-expected-asm-or---attribute---before-token/2376/4 "2017-03-06T09:19:10Z")

</div>

I have created a new project which I have created as below  
new-\>project-\>c++ application-\>C++ Hello world Project-\>(toolchain)legato linux GCC-\>Finish

now I have build it but there symantic errror showing at ‘cout’, ‘endl’, ‘std’ : symbol could not be resolved.

code:

```
#include <iostream>
using namespace std;

int main() {
    cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
    return 0;
}

```

I just want to add code for my project in c++ language and burn it in mangOH borard for some application  
how can create C++ project and build it successfully ?

---

<div class="post-metadata">

**Author:** ![daav](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/daav/32/64_2.png) [@daav](https://forum.legato.io/u/daav)\
**Post date:** [March 6, 2017, 9:40am UTC](https://forum.legato.io/t/error-type-expected-asm-or---attribute---before-token/2376/5 "2017-03-06T09:40:05Z")

</div>

You can do C++ in Legato apps.  
Once your Legato app project is created, you can either rename the main .c file to .cpp, or add a new .cpp file.  
The only thing to take care about is to explicitly declare pure C code fragments (and all usage of the Legato apis will be) as such in your .cpp files.

Example (if you rename the .c file to a .cpp file):

```
extern "C" {

#include "legato.h"

COMPONENT_INIT
{
    LE_INFO("Hello, world.");
}

}

// Some C++ stuff here
class name {
public:

private:
};

```

Inclusion of .h files containing C stuff will have to be done **inside** the **extern “C”** block, and inclusion of .h files containing C++ stuff will have to be done **outside** of it.

By the way, if you rename your .c file, please note that the **Component.cdef** file needs to be updated accordingly. Fortunately, this is managed automagically if you’re renaming the file inside DS.

---

<div class="post-metadata">

**Author:** ![rups](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@rups](https://forum.legato.io/u/rups)\
**Post date:** [March 6, 2017, 12:25pm UTC](https://forum.legato.io/t/error-type-expected-asm-or---attribute---before-token/2376/6 "2017-03-06T12:25:19Z")

</div>

Thank you so much now I am able to build it.

now I have added class in main ‘.cpp’ file and access that class method through one main() method.  
this main() method I have called at COMPONENT\_INIT micro , as in legato application this micro acts as initialization main method of application.  
But I am facing one error related to class which I have generated in separate ‘cpp’ and ‘.h’ file.

**code :**  
**mainComponent.cpp**

```
#include "CfirstSampleclass.h"

extern "C"{
#include "legato.h"

}

class mainClass
{

public:

    mainClass()
    {

    }

    ~ mainClass(){};

    void funcOne()
    {

     LE_INFO("Hello, Rupali.");

    }

};

int main()
{

mainClass obj;
obj.funcOne();

CfirstSampleclass firstObj;
firstObj.ffoo();

return 0;

}

extern "C" {

COMPONENT_INIT
{
    LE_INFO("Hello, world.");
    main();
}
} 

```

**CfirstSampleclass.cpp code:**

```
#include "CfirstSampleclass.h"
extern "C"{
#include "legato.h"
}

CfirstSampleclass::CfirstSampleclass() {

}

CfirstSampleclass::~CfirstSampleclass() {
    // TODO Auto-generated destructor stub
}

void CfirstSampleclass::ffoo()
{
    LE_INFO("Now in to CfirstSampleclass: ffoo() ");

}

```

I am getting error as :  
undefined reference to `CfirstSampleclass::CfirstSampleclass()' undefined reference to `CfirstSampleclass::ffoo()’

Though I have included header of this cpp file, I am getting this reference error.  
please help me to get out of it.

---

<div class="post-metadata">

**Author:** ![daav](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.legato.io/daav/32/64_2.png) [@daav](https://forum.legato.io/u/daav)\
**Post date:** [March 6, 2017, 12:53pm UTC](https://forum.legato.io/t/error-type-expected-asm-or---attribute---before-token/2376/7 "2017-03-06T12:53:09Z")

</div>

Mmmm, just looks like your **CfirstSampleclass.cpp** file is not referenced in your **Component.cdef** file.

Tip: use **Ctrl+space** for auto-completion in the **sources** section.

(By the way, in next DS release, we’re working on an improvement to automatically update the **Component.cdef** file when source files are created/deleted)

---

<div class="post-metadata">

**Author:** ![rups](https://avatars.discourse-cdn.com/v4/letter/r/5e9695/32.png) [@rups](https://forum.legato.io/u/rups)\
**Post date:** [March 7, 2017, 5:00am UTC](https://forum.legato.io/t/error-type-expected-asm-or---attribute---before-token/2376/8 "2017-03-07T05:00:38Z")

</div>

Thank you so much. 🙂  
I have added manually ‘.cpp’ name in ‘cdef’ file.  
now able to build and run successfully.
