why do I get this error building a static library for my iPhone project using XCode 4?

依然范特西╮ 提交于 2020-01-06 05:02:31

问题


I have an existing iPhone application, and I just wanted to make a static library out of the code, so that I can use it by a separate test application (within the workspace). The application compiles fine, but when I try to compile the library version (which has the same code files) I get the following error:

  • Lexical or Preprocessor Issue - "MyClass.h" file not found

However, the application still runs, even through there is this error. In fact when I compile the application (which uses the static library) it initially says no errors, and then after a second or two the above mention error then appears.

I'm basically doing:

  1. Create a new target in the project using the Coco Touch Static Library
  2. Add the .m files in the targets "Compile Sources"
  3. Adding the .h files in the targets "Copy Headers"
  4. Adding the same set of libraries in the "Link binaries with libraries"
  5. Go into the Profile and modified the Target to be RELEASE

Any suggestions? Am I missing a step here?


回答1:


I'll have a stab at this :-) I think it might be that MyClass.h has been set to private. Thus it is not added to header directory when you create the static library. You should check to see if this is so by checking the output header directory. If the header file is missing, then it's pretty sure thats whats going on.

Secondly, why use a seperate app for testing and therefore require building a static library at all? I have several static libraries and apps which I unit test with GHUnit. I do it by simply adding a new app target and configuring it to run the GHUnit iOS app. I can then add the classes I want to test and any testing frameworks such as OCMock without having to create separate projects. Basically it sounds like your testing methodolody is perhaps more complex than necessary. :-)




回答2:


So, the issue turned out to be I had "-ObjC" set in the "Other Link Flags" option, which I'd put there as at one stage trying to get things working I read this was required - Dereks advice to review the compilation log worked well here



来源:https://stackoverflow.com/questions/6195455/why-do-i-get-this-error-building-a-static-library-for-my-iphone-project-using-xc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!