您的位置:首页 > 其它

'filename.h' file not found with <angled> include, use "quotes" instead. 问题详解

2016-04-02 13:00 1041 查看
http://stackoverflow.com/questions/17465902/use-of-external-c-headers-in-objective-c

下面 有个解释的设置步骤 不过 不正确 好像还是最佳回答吧,正确的设置 为 http://blog.csdn.net/jeffasd/article/details/51043492
In my iOS project I need to use an external library written in C++. The C++ header files are all in one directory.

I've added these C++ headers to my Xcode project, and also specified a header search path (in Build Settings).

The issue is that these C++ headers include each other using < > angle brackets. This results in:
'filename.h' file not found with <angled> include, use "quotes" instead.


The weird thing is that Xcode does not complain about all headers. Also the same header #include'd in one file is fine, while an issue when #include'd in another. I think this is caused by the fact that these headers #include each other.

Why doesn't doesn't the search path work?
Is there a way to resolve this without modifying these header files?

Thanks!

c++ ios objective-c xcode include-path
shareimprove
this question
edited Jul
4 '13 at 9:07

asked Jul 4 '13 at 8:50





meaning-matters
5,83022149

Do you have the sources and the Xcode project of that C++ library? – CouchDeveloper Jul
4 '13 at 8:58
@CouchDeveloper No I don't. – meaning-matters Jul
4 '13 at 9:01
4
Does setting the "Always Search User Paths" build setting help? – Martin
R Jul
4 '13 at 9:16
@MartinR Holy smokes, yes! :-) Put it as answer and I will reward. I've removed the
-I
,
nice. Why did
-I
not
work? – meaning-matters Jul
4 '13 at 9:23
add
a comment


3 Answers

activeoldestvotes

up vote12down
voteaccepted
#include <bla.h>


is meant for standard library or framework headers, and the search strategy Is different than that used for
#include "bla.h"


See for example

What
is the difference between #include <filename> and #include "filename"?

As a workaround, you can set the Xcode build setting "Always Search User Paths" to YES.

shareimprove
this answer
edited Jul
4 '13 at 9:38

answered Jul 4 '13 at 9:28





Martin R
210k17346422

1
Note that setting "Always Search User Paths" to YES may cause header issues. It's strongly recommended to set it to
NO, and that's the correct way. It's still only there for backward compatibilities. The third party library's headers should be included via angle brackets. – CouchDeveloper Jul
4 '13 at 10:14
@CouchDeveloper: It was meant as a workaround, but you are right and your answer is problably the better solution. – Martin
R Jul
4 '13 at 10:52
@CouchDeveloper agree that the this setting should be set to NO, but is there anything undesirable setting this setting
to YES in the context of building an embedded framework? – Chris
Holloway Apr
15 '15 at 14:16
add
a comment


up vote7down
vote
Starting from a "blank" application project:

Create a folder "Libraries" in your application's project - preferable as a sibling to your MyApp.xcodeproj file, but it can be anywhere. Create subfolders for each Configuration (Debug, Release, etc.) and possibly for each architecture (armv7, armv7s, arm64)
unless the binary is universal binary archive containing all architectures.

Get the headers of the third party library and the static library binaries (possibly more than one for different platforms, Configurations and architectures) and move them into the "Library" folder into corresponding subfolders (which you may need to create):

For example, assuming you had a universal binary (armv7, armv7s, arm64) and Debug and Release versions of that library: Now, the folder structure is assumed to be as follows:
$(SRCROOT)/Libraries
Debug-iphoneos
include
ThirdParty
third_party.hh
...
libThirdParty.a
Release-iphoneos
include
ThirdParty
third_party.hh
...
libThirdParty.a
MyApp.xcodeproj


"Library Search Paths" Build Setting:

Drag the "Libraries" folder into your Xcode project. This may automatically create a library search path in the build settings. Please verify this, and if it is not correct, fix it.

Given the example, add the following library search paths for Debug and Release Configuration:

Debug: Library Search Paths:
$(SRCROOT)/Libraries/Debug-iphoneos


Release: Library Search Paths:
$(SRCROOT)/Libraries/Release-iphoneos


You may have different library search paths for particular Configuration and Target platform pairs. Set different path's in the build setting accordingly.

"Header Search Paths" Build Setting:

Given the example, add the following header search path to the Debug and the Release Configuration:

Debug: Header Search Paths:
$(SRCROOT)/Libraries/Debug-iphoneos/include


Release: Header Search Paths:
$(SRCROOT)/Libraries/Release-iphoneos/include


Likewise, you may have different paths for particular Config/Target pairs - although the headers may be the same.

Link your app against the C++ standard library by adding
-lc++
to
the Other Linker Flagsbuild setting.

Import the header in your files as follows:
#import <ThirdParty/third_party.hh>


shareimprove
this answer
edited Apr
17 '14 at 21:28

answered Jul 4 '13 at 10:05





CouchDeveloper
10.9k21741

That helped, since that error was target-dependent in my case. – Thibault
D. Jan
21 '14 at 7:38
Epic, first time I can make the angle includes work with a 3rd party library that I have in my project because I want
to patch it. Thanks. – aledalgrande Nov
17 '14 at 18:33
add
a comment
up vote1down
vote
In XCode after setting the "User Header Search Paths" to point to your library's directory, you also have to make sure that a field called "Always Search User Paths" is set to "Yes"

This solved the problem I was having: with <boost/signals2.hpp> file not found with <angled> include, use "quotes" instead.

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: