programing

xcode 프로젝트에 포함 경로를 설정하는 방법

minecode 2022. 8. 11. 21:38
반응형

xcode 프로젝트에 포함 경로를 설정하는 방법

Objective-C Xcode 프로젝트에서 C 라이브러리를 사용하려고 합니다.

라이브러리 디렉토리 구조는 다음과 같습니다.

-- include/
    |-- config.h
    |-- lib/
    |    |-- file1.h
    |    |-- file2.h
    |    |-- file3.h

라이브러리의 문서에서는 file1.h를 포함하도록 되어 있으며 file1.h에는 file2.h와 file3.h가 포함됩니다.

file2.h 와 file3 의 인크루드 에러 「file not found」가 표시됩니다.h'. 파일1.h에는 다음과 같은 방법으로 포함됩니다.

#include <lib/file1.h>
#include <lib/file2.h>

여기서 읽었습니다.이 앵글브래킷은 #include가 포함된 파일과 같은 디렉토리에서 검색하는 것이 아니라 INCLUDE 환경변수에 의해 지정된 경로를 따라 포함 파일을 검색하도록 프리프로세서에 지시합니다.

[ Product - ]> [ Edit Scheme ] edit [ INCLUDE ]code [ Xcode ]를하여 [Edit Scheme]으로 설정합니다./the-whole-path-to/include/파일을 찾을 수 없습니다.

file1.h를 다음과 같이 변경하면 파일이 정상적으로 포함됩니다.

#include "file2.h"

하지만 도서관에 있는 모든 파일에 대해서는 그렇게 하고 싶지 않아요.

어떻게 하면 고칠 수 있을까요?

XCode 버전 5.0.2에서는 이를 실현하는 가장 좋은 방법은 타깃의 [Search Paths]페인에 추가하는 것입니다.이것을 찾는 것은 믿을 수 없을 정도로 의도적이지 않았다.저처럼 혼란스러운 분들을 위해 제가 하게 된 계기는 다음과 같습니다.

왼쪽 열에서 프로젝트 탐색기 아이콘(폴더 모양)을 클릭합니다.그런 다음 프로젝트 항목을 클릭합니다.메인 페인에 다수의 설정이 표시됩니다.이 창의 맨 위에서 "빌드 설정"을 클릭합니다.여기엔 수많은 엔트립이...검색 경로라고 하는 것을 포함...그러나 여기에 검색 경로를 추가할 수 없습니다.이 때문에 이 페인의 맨 위에 있는 프로젝트 이름이 풀다운임을 알 수 있을 때까지 한참 동안 이를 갈았습니다.이 풀다운에서 타깃을 선택하면 "헤더 검색 경로"를 더블 클릭하여 필요한 편집을 수행할 수 있습니다.

오, 미친 GUI의 즐거움.

알아냈어.

'기타 C 플래그'의 빌드 설정에 I 플래그를 추가하면 됩니다.

타겟 에서 "C Flags하여 "Other C Flags"를 추가합니다.-I/path-to-include/

스크린샷이.enter image description here

이것을 시험해 보세요.

-합니다.
2 - 중간 Xcode 페인으로 프로젝트가 선택되었는지 확인합니다.
3 - 중앙 Xcode 창의 상단에 있는 "빌드 설정"을 선택합니다.
4 - "빌드 설정" 바로 아래에 "모두"와 "조합"이 선택되어 있는지 확인합니다.
5 - "빌드 설정" 바로 아래의 검색 필드에 헤더를 입력합니다.

You should see the search path fields ready for editing in the middle pane.

I solved this in Xcode 5.0.1 using the project Build Settings (as John and Ian noted above, but I cannot comment due to <50 rep).

New info:

When adding includes to User Header Search Paths, I also had to change Always Search User Paths to Yes.

When adding includes to (non-User) Header Search Paths, Always Search User Paths is not required.

Although this works, it is probably better to put it under the "Search Paths" tab instead.

Either you can use "Other C Flags" or use "HEADER_SEARCH_PATHS", to specify the include paths, to look for header for your executable.

In 2021, Xcode v. 12.4, the solution seems to be:

Project->Targets->General->"Scan All Source Files For Includes"-> set to "Yes"

This worked for me.

However, this might backfire if you have multiple versions of a specific .h file, probably not a good practice but it's possible if you have lots of sub-directories with their own mini-projects and similarly named include files.

ReferenceURL : https://stackoverflow.com/questions/14134064/how-to-set-include-path-in-xcode-project

반응형