views:

293

answers:

2

I get the following error when I try to build (Build->build) a unit test. My unit test is a logic test (it does not run on the device).

Things that are probably related to my problem are: I am using libxml2 and a wrapper around it (which i found at cocoawithlove).

This wrapper has some C functions defined (it is not an Objective C class with @interface and @implementation). The function i am using (and on which the error is occuring) is

NSArray *PerformHTMLXPathQuery(NSData *document, NSString *query);

The strange thing is that all works perfectly well, when I build my application and run it in the simulator. However when i try to run my unit test, i get this error:

/Users/me/XCodeWorkspace/MyProject/XPathQuery.h:15:0 Expected '=', ',', ';', 'asm' or 'attribute' before '*' token in /Users/me/XCodeWorkspace/MyProject/XPathQuery.h

There are some related questions here, but none of them seems to solve my problem. In particular: http://stackoverflow.com/questions/990906/iphone-error-expected-asm-or-attribute-before-foo But here some c++ code should be included.

Thank you for help.

A: 

Most likely the compiler is trying to compile your file as C code and not Objective-C code. It's seeing something strange like NSString, which isn't part of the C language, so it's barfing at you.

If you change the file to Objective-C or Objective-C++, it should work. (You can do this be getting info on the file and changing the source type)

Dave DeLong
My filetypes are set to Objective-C. When I change the filetype to C (and select my application as the active target) I indeed get the same error. But when I take the working setup (with filetypes set to objective-C) and I switch the target to my LogicTests.octest I get this error. I also get a "warning: no rule to process file '$(PROJECT_DIR)/XPathQuery.h' of type sourcecode.c.h for architecture i386." Does anybody have an idea? Thanks for everything!
brbr
I tried to include these two files (which can be found at: http://cocoawithlove.com/2008/10/using-libxml2-for-parsing-and-xpath.html) into some of the sample projects. When I include into iphoneUnitTests sample project I get the same error when I hit build. However when I include them into a project without tests, there is no such error when I compile. The unit tests (logic tests that do not run on the device) are tied to the compilation... Is there any chance to include these wrapper files? Or: Do I have to rewrite them as true Objective-C files with methods instead of functions??
brbr
A: 

After trying to change the filetype of my files (I tried several different things and none of them helped) I decided to rewrite these files as Objective-C files with methods instead of functions. This solved my problem.

brbr