Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

xcode4

I have a project that won't build because the compiler (?) can't seem to find the .h files. I have tried using the full path, relative path and setting the Project Search Paths (both Header and User Header) and nothing seems to work. What I find very strange is even with the full path it gives an error: No such file or directory (the file does indeed exist in the specified path).

Can anybody give some suggestions on what could be the problem? I would certainly appreciate it.

import statements:

#import <Foundation/Foundation.h>
#import <zxing/common/Counted.h>
#import <zxing/Result.h>
#import <zxing/BinaryBitmap.h>
#import <zxing/Reader.h>
#import <zxing/ResultPointCallback.h>

Headers are located in:

/Users/rolfmarsh/iPhoneCodeLibrary/BarcodeLibrary/zxing-1.6/cpp/core/src/zxing

Header search path is:

$(inherited)
"$(SRCROOT)/zxing/common"

and

/Users/rolfmarsh/iPhoneCodeLibrary/BarcodeLibrary/zxing-1.6/cpp/core/src

Full path of the include files:

/Users/rolfmarsh/iPhoneCodeLibrary/BarcodeLibrary/zxing-1.6/cpp/core/src/zxing/Result.h
like image 482
Spokane-Dude Avatar asked Jun 08 '11 19:06

Spokane-Dude


2 Answers

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.

like image 61
Max MacLeod Avatar answered Nov 04 '22 18:11

Max MacLeod


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.

like image 39
mircaea Avatar answered Nov 04 '22 19:11

mircaea