You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

c++ framework

I'm trying to create a framework using some c++ libraries... already written, tested and (fortunately) working. No problems about compiling framework, but when I added it into my obj-c app, gcc gave me a bunch of errors in (public) header files: parse errors, sintax errors, undeclared variables and so on...
Can you explain me why? Are there any compiling conflicts between obj-c and c++? Are there some particular configurations to set to make it work?

macbook pro, xcode 2.4 Mac OS X (10.4.8)

Posted on Nov 4, 2006 4:17 AM

Reply
6 replies

Nov 4, 2006 4:18 PM in response to iSasha

[update] I renamed myApp.m into myApp.mm to make it know to compile obj-c++... ok, that was pretty easy, but it gives me still some errors (even if less than before). I noticed that header files (where these errors are reported) are considered c headers, not c++ headers... Could my problem be this?

Nov 4, 2006 7:26 PM in response to iSasha

I noticed that header files (where these
errors are reported) are considered c headers, not
c++ headers... Could my problem be this?


Hmmm. I don't have any experience with C++, and doing this kind of thing. But I did find a suggestion somewhere that you should try importing the Cocoa header to your header file. That might make Xcode treat it as an Objective-C++ header, (which is what putting ".mm" on the end of your file name does:

<pre class="command">#import <Cocoa/Cocoa.h></pre>

charlie

Nov 5, 2006 4:05 AM in response to Charles Minow

It doesn't work... I tried forcing the framework compiling with c++, using compile sources as" and "c dialects to precompile" options in build tab of target inspector. Then I imported my framework into myApp (compiled as obj-c++), but same errors (in my specific case, somewhat about typedef enum...).
Using inspector for every single .h file, it's also possibile to set file type as "sourcecode.cpp.h", but then inspector on public header files of the imported framework shows them still as "sourcecode.c.h".
Any ideas?

Nov 5, 2006 9:29 AM in response to Charles Minow

error: conflicting declaration 'typedef int BOOL'
error: 'BOOL' has a previous declaration as 'typedef signed char BOOL'
// ok, redeclaration...

error: expected identifier before numeric constant
error: expected `}' before numeric constant
error: expected unqualified-id before numeric constant
error: expected constructor, destructor, or type conversion before ';' token
error: 'PrefType' does not name a type
// these are about the line:
// typedef enum { TYPE_INT, TYPE_STRING, TYPE_FLOAT, TYPE_BOOL } PrefType;

error: expected declaration before '}' token
// at the end of the file...

Once solved these errors, probably there will be some others in the following headers: this is the first of the whole hierarchy. Is it the right way to solve the problem? Or is it a compiler configuration problem?

Nov 5, 2006 9:43 AM in response to iSasha

error: conflicting declaration 'typedef int BOOL'
error: 'BOOL' has a previous declaration as 'typedef
signed char BOOL'
// ok, redeclaration...


Okay, this one is easy. BOOL is defined in objc.h like so:

<pre class="command">typedef signed char BOOL;</pre>So you are declaring it in your c++ file as a different type. If I had this problem, I'd probably try changing the declaration to something else, like Boolean or MYBOOL in the c++ framework. But I'm not sure it that's the "right" way or not.

error: expected identifier before numeric constant
error: expected `}' before numeric constant
error: expected unqualified-id before numeric
constant
error: expected constructor, destructor, or type
conversion before ';' token
error: 'PrefType' does not name a type
// these are about the line:
// typedef enum { TYPE_INT, TYPE_STRING, TYPE_FLOAT,
TYPE_BOOL } PrefType;


Hmm. I see a TYPE_BOOL there, so it's possible that's just related to the redeclared BOOL above. Like I said, I don't know that much about c++, so I'm a bit lost with some of this stuff.

charlie

c++ framework

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.