Why can't XCode 4 find my .h files during a build?

若如初见. 提交于 2019-11-29 04:52:25

I also had quite a bit of pain with ZXing's dependencies. Here's some tips that will hopefully be of assistance to others with similar issues.

This line does an import:

#import <zxing/common/Counted.h>

For the compiler to find Counted.h, the header search path must be specified.

Now, because the import statement will look for Counted.h relative to two subfolders zxing/common, we need to give it the parent folder of zxing.

In this case, the parent folder is going to be something like:

/ .. my full path here ../cpp/core/src/

So, under the src directory you'll find zxing.

How do we configure this in Xcode? Best to do it relatively. Otherwise, the project will fail on a different user's machine.

To do this, we specify a path relative to the project directory. As follows:

$(PROJECT_DIR)/../cpp/core/src

That goes in the Header Search Path of Build Settings for the ZXingWidget target.

The crucial thing with this header path stuff is to specify the relative directory to search from. In our case, we specify search relative to $(PROJECT_DIR). That variable specifies the directory of our subproject ZXingWidget.

Other caveats. Be careful to specify these in the build settings of your target. If you do it at project level you'll still need to specify it at target level using the $(inherited) variable.

Also, don't forget that the build transcript can be very useful. Look at the header paths included with the -I flag.

As a general debugging technique, I like to specify the absolute path in my settings. That gives a clean build and I know that the files can be included, and where they definitely are. Having done that I then use the $(PROJECT_DIR) to specify a relative path.

I am posting this in order to make things simple for newbies like me that are integrating zxing qr reader in their projects and to bring closure to a couple of threads related to zxing integration.

1. Main thing - Be absolutely sure you have the latest version.

http://zxing.googlecode.com/svn/trunk/

[By now, January 18th, you will have no more issues with that zxing/common/ folder. Easiest fix for this: get the latest code!]

2. Go to zxing -> iphone -> ZXingWidget.

Drag ZXingWidget.xcodeproj file and drop it onto the root of your Xcode project's "Groups and Files" sidebar.

[you should now have ZXingWidget.xcodeproj listed there and it has to drop down and list it's content]

3. In the same place, project navigator, select:

Your project file - > Targets -> 'your project name' -> Build phases -> Link binary with libraries.

You should find a folder named 'Workspace'. Add 'libZXingWidget.a' from within.

4. Still in Build phases, expand Target Dependencies and add ZXingWidget.

5. Select Build Settings and search for Header Search Paths. You need to add 2 records to Header Search Paths. You do not need to associate values to User Header Search Paths. You achieve this by double clicking the column on the right. A small popover window will apear. Use the + button to add the first record. Add:

../zxing/iphone/ZXingWidget/Classes

Now use the + button to add the second record. Add:

../zxing/cpp/core/src

These are the values I use. These values work because I use the same folder to host both my project and the zxing folder.

[Be sure to refer your folder properly in case you decide to have a different file structure.]

6. Go back to Build Phases and add the following ios frameworks required:

AVFoundation

AudioToolbox

CoreVideo

CoreMedia

libiconv

AddressBook

AddressBookUI

7.

Create a set of files (.h&.m) and change it's .m extension to .mm

8. Test the integration by including the following in the file previously created:

#import <ZXingWidgetController.h>
#import <QRCodeReader.h>

At this point you should run into missing files only if you are not running the latest version. Hope this helps.

Some things to check:
- file permissions
- can you build from the command line using xcodebuild?

danielsalare

I went over many blog posts on how to fix this. This one helped me well.

http://alwawee.com/wordpress/2011/12/01/zxingwidgetcontroller-h-not-found-zxing-installation-problem-solution/

The problem was that header search paths were not properly defined. So I...

1) Downloaded zxing 2.1

2) From the download I copied: iphone, cpp, objc and readme and pasted in a folder names "zxing"

3) I added the new folder "zxing" to my project (on my mac) not to the xcode app.

4) From the created folder zxing I dragged the zxingwidget.xproje to my xcode project

5) I followed all the steps you find in all the blogs

KEY TO SOLVE THIS

6) I followed this steps for xcode errors https://stackoverflow.com/a/14703794/1881577

7) I followed this steps for header path file errors http://alwawee.com/wordpress/2011/12/01/zxingwidgetcontroller-h-not-found-zxing-installation-problem-solution/

IMPORTANT NOTE: I had to do follow step 7) twice, I had to select the project target and assign header paths, and I had to select the project project and assign header paths.

8) Build zxingwidget project (from the scheme select options)

9) Build Run the project.

Hope this helps other people as well.

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