sdwebimage: UIImageView+WebCache.h: No such file or directory

11,645

Solution 1

To add the needed header files to the build path do the following.

  1. Select your project file
  2. Select your target
  3. Select Build settings
  4. In the search box enter 'header search paths'
  5. For the Release add "$(SOURCE_ROOT)/SDWebImage" (thats with quotes).

This will work when importing like this #import <SDWebImage/UIImageView+WebCache.h>

Solution 2

I also use SDWebImage.
In my experience I didn't do anything with the linker flags etc.
You only have to add the classes in your project and simply import the "UIImageView+WebCache.h" in your class' header like this:

#import "UIImageView+WebCache.h"

and if you want to use it on an UIImageView object, just use the method

setImageWithURL:placeholderImage:

you can refer to their github for more info

Solution 3

I just ran into this problem and have solved it.

The issue is that when you "drag" the SDWebImage xcode project to your project, Xcode only create a reference to point to those files needed. When you are in debug mode it's fine, it knows where to find those file. However, when you want to archive it (packing everything to be self-contained), it couldn't find it from your search path.

Although you have added $(BUILT_PRODUCTS_DIR) to your search path, but if the actual files that you downloaded are not physically located in your $(BUILT_PRODUCTS_DIR), then Xcode won't find them. This was the problem for me since my SDWebImage files were still sitting in my download folder.

What you want to do is:

1.Move the SDWebImage folders to a place where you won't accidentally delete it. Notice once you've done that, the SDWebImage project file will become red since it's physical location is moved. And it's wired that I could not delete that reference in Xcode, what I ended up doing is add that file again (choosing from the location where I just move it too). You will end up with a red SDWebImage.xcodeproj in your project navigator which you can not delete. It's very annoying but it won't affect anything. 2. If the location you move the SDWebImage stuff to is not in your $(BUILT_PRODUCTS_DIR), then you either move that inside $(BUILT_PRODUCTS_DIR) or as I do, add the path to Target -> Build Settings -> Search Paths -> User Header Search Paths.

Archive and it should work now.

Solution 4

I faced this same problem and was about to go crazy. Like Ravi, I followed the static installation instructions as closely as possible.

I saw the auto suggest for UIImageView+WebCache.h when I was typing #import, but it keeps throwing file not found.

In the end, it was this. In header search paths,

“$(BUILT_PRODUCTS_DIR)” - Wrong.

$(BUILT_PRODUCTS_DIR) - Right.

Embarrassed but now it's working right =)

Solution 5

I've been dealing with this problem for the past hour and noticed something that hasn't been mentioned: Make sure that when you up update header search paths that the "Recursive" option is selected! Otherwise the compiler will not check subfolders.

Worked for me...

Share:
11,645
Ravi
Author by

Ravi

Updated on June 04, 2022

Comments

  • Ravi
    Ravi almost 2 years

    I am fairly new to ios development - trying to use sdwebimage in my iphone project. I believe I completed all basic setups as required. But when I build, I get this error: No such file file or directory near this line:

    #import "UIImageView+WebCache.h"
    
    • Yes I have added Target Dependencies
    • I have added libSDWebImage.a in Link Binary With Libraries
    • I have -all_load -ObjC in Other Linker Flags
    • I also tried the -force_load ${BUILT_PRODUCTS_DIR}/libSDWebImage.a (64bit mac)
    • My Use Header Search Paths is : $(BUILT_PRODUCTS_DIR)
    • I cleaned the project and rebuilt - but no use.

    Build keeps failing. Again, XCode4 code completion "resolves" when I type #import "UI & hit "ctrl+space" which means the lib is visible to xcode. Any pointers will be super helpful. Thanks.