开发者

Including a C++ header in an Objective-C project yields "Expected * before *" errors

I'm new to Objective C and (unfortunately) also to the project I am working on. I was given a small sample project that refers to work from my predecessors (in C++) and uses it for an iPhone app (Objective C). Rather than extending the sample (it was quick n dirty and I didn't wanna mess around in it) I created a new project from scratch for my stuff. To get it working I need to set up the same links to the previous libraries as the other one, but although in my settings I can't find any differences to the existing p开发者_高级运维roject it won't do the trick.

With the help of colleagues and Google I reached this:

1) The project includes two library files, libyid.a and libvrpn.a, via Xcode's "Add files" dialogue. It automatically added the libraries' paths to the Library Search Paths in the Build Settings and the files show in the projects folder structure in XCode. As far as I can tell this bit seems not to cause problems. Edit: if i remove these files from the project I get the same errors. I'm now thinking that XCode can resolve the headers, but can't find the implementation and that the libraries may have been there but not been properly set up?

2) One of my custom classes uses

#import "DisplayYid.h"

I added the path to the file's location to the "Header Search Paths" in the Build Settings and it seems to be found alright. (I also added the file via the "Add files" dialogue at some point, but it didn't change anything, so I left it this way)

Now the problem: in

@interface YidController : NSObject { 
    DisplayYid *myYid;
    // (etc. etc.)
}

the identifier "DisplayYid" seems to remain unknown (Error: Expected specifier-qualifier-list before DisplayYid). In addition, all the class definitions in the headers that DisplayYid itself includes yield

error: expected '=', ',', ';', 'asm' or '__attribute__' before '__declspec'

My knowledge here is unfortunately very limited, but it seems to me that XCode can find the headers in question, but somehow would expect the content in a different format/language? When I had DisplayYid.h included as a file in the project hierarchy I tried to set its file type in the file inspector to "C++ header" (as suggested by some hits I found on Google for my problem), but this doesn't change a thing. I feel I am missing some tiny but crucial detail, but am not sure-footed enough in any of this to test around further. Hopefully somebody sees my missing link? And sorry if this is too lengthy, I simply tried to include the detailed steps in case this is were the problem lies.

Thanks in advance for your time ;)

EDIT: This question seems to be the same problem, especially the fact that he gets the error multiple times from files simply copied. But none of the suggested solutions seem to work for me.


It's been a while now, but I got hold of the guy who worked on this previously. It took him an hour, but he found the missing bit: In the project settings, two compiler flags needed to be set:

-DIOS (defining the flag iOS) -x objective-c++

From there on everything went fine. Since this was a rather project-related question and solution, should I delete it all together?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜