Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10
Accepted Solution

expected '=', ',', ';', 'asm' or '__attribute__' before Error for C++ header file

Description Resource Path Location Type
expected '=', ',', ';', 'asm' or '__attribute__' before 'GeoLocation'

 

I've searched high and low in Google to find a resolution to this.  The header file is GeoLocation.hpp and it is at the class declaration "class GeoLocation'.

 

Any thoughts?  My C++ is a few years old.

Please use plain text.
Developer
rcmaniac25
Posts: 1,805
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.634 Dev OS, Z30 (STA100-5)-10.3.1.634 Dev OS, Passport (SQW100-1)-10.3.0.1418, PlayBook (16GB)-2.1.0.1917

Re: expected '=', ',', ';', 'asm' or '__attribute__' before Error for C++ header file

Could you maybe post the code for the class (at least the start and end)?
---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

Re: expected '=', ',', ';', 'asm' or '__attribute__' before Error for C++ header file

class GeoLocation

{

  public:

    GeoLocation();

    ~GeoLocation(); 

}; 

Please use plain text.
Developer
rcmaniac25
Posts: 1,805
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.634 Dev OS, Z30 (STA100-5)-10.3.1.634 Dev OS, Passport (SQW100-1)-10.3.0.1418, PlayBook (16GB)-2.1.0.1917

Re: expected '=', ',', ';', 'asm' or '__attribute__' before Error for C++ header file

My testing tells me that you are trying to use a C++ class (class only exists in C++ as I expect you know) in a C project.

 

The key is:

#if defined (__cplusplus) || defined(__CPLUSPLUS__)

 so that it only compiles within a C++ "context" (I guess you would call it).

 

Test case:

//------Test 1 (just the class)
class GeoLocation //Error
{
  public:
    GeoLocation();
    ~GeoLocation();
};

//------Test 2 (extern C)
extern "C" {
class GeoLocation //Error
{
  public:
    GeoLocation();
    ~GeoLocation();
};
}

//------Test 3 (extern C++)
extern "C++" { //Error
class GeoLocation
{
  public:
    GeoLocation();
    ~GeoLocation();
};
}

//------Test 4 (only use for C++)
#if defined (__cplusplus) || defined(__CPLUSPLUS__)
class GeoLocation //No error :D
{
  public:
    GeoLocation();
    ~GeoLocation();
};
#endif

//------Test 5 (only use for C++ and extern C++)
#if defined (__cplusplus) || defined(__CPLUSPLUS__)
extern "C++" {
class GeoLocation //No error :D
{
  public:
    GeoLocation();
    ~GeoLocation();
};
}
#endif

 I did the code in a similar fashion (with the if statement) then did GeoLocation::GeoLocation() and everything worked and compiled fine.

---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

Re: expected '=', ',', ';', 'asm' or '__attribute__' before Error for C++ header file

I'll give it a try later.  Thanks for looking into this.

Please use plain text.
Developer
rcmaniac25
Posts: 1,805
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.634 Dev OS, Z30 (STA100-5)-10.3.1.634 Dev OS, Passport (SQW100-1)-10.3.0.1418, PlayBook (16GB)-2.1.0.1917

Re: expected '=', ',', ';', 'asm' or '__attribute__' before Error for C++ header file

No problem. I had the issue at some point and figured it out somehow.
---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

Re: expected '=', ',', ';', 'asm' or '__attribute__' before Error for C++ header file

#if defined (__cplusplus) || defined(__CPLUSPLUS__)

 

worked fine and you have to do the same in the implementation file (.cpp) around all the methods too.

Please use plain text.
Developer
jtegen
Posts: 6,541
Registered: ‎10-27-2010
My Device: HTC One, PlayBook, LE Z10, DE Q10

Re: expected '=', ',', ';', 'asm' or '__attribute__' before Error for C++ header file

Its odd that you have to do this for any reference to the C++ implementation or object.  Even had to do:

 

#if defined(__cpluplus) || defined(__CPLUSPLUS__)

static GeoLocation *geo_service;

#endif

 

When creating the library, C++ was selected.  Is there a way to check that the library project is compiling against the C++ compiler?

Please use plain text.
Developer
rcmaniac25
Posts: 1,805
Registered: ‎04-28-2009
My Device: Z10 (STL100-4)-10.2.1.3253, Z10 (STL100-3)-10.3.1.634 Dev OS, Z30 (STA100-5)-10.3.1.634 Dev OS, Passport (SQW100-1)-10.3.0.1418, PlayBook (16GB)-2.1.0.1917

Re: expected '=', ',', ';', 'asm' or '__attribute__' before Error for C++ header file

That would be what the if defined is doing (or at least I assume so). It's odd but the underlying compiler for qcc is gcc and I doubt that this is just a QNX thing.
---Spends time in #blackberrydev on freenode (IRC)----
Three simple rules:
1. Please use the search bar before making new posts.
2. "Like" posts that you find helpful.
3. If a solution has been found for your post, mark it as solved.
--I code too much. Well, too bad.
Please use plain text.
Retired
cdamus
Posts: 45
Registered: ‎10-25-2010
My Device: Bold 9700

Re: expected '=', ',', ';', 'asm' or '__attribute__' before Error for C++ header file

Hi, John,

 

Sorry to be jumping in so late in this thread, but it looks like you're having to go out of your way to make changes in your code that seem like they shouldn't be necessary.

 

Are you including C++ headers in C-language headers or other source files?  Is the C-language content in some of these headers, mixed together with C++ content?  In that case, it is to be expected that C++ content has to be conditionally excluded because it's a different language than C.

 

Or are your projects C++ throughout, in which case none of this should be necessary, and it in fact indicates a problem in the tooling?  Are the errors that you see without these conditional exclusions compiler errors, reported by project build, or indexer errors, manifest only in the editor, and possibly as little bug icons instead of the usual red Xes?

 

Cheers,

 

Christian

Please use plain text.